实际上WP_Comment_Query
类几乎支持您想要的所有内容。您可能想使用post_author
获取评论or user_id
. 两者的作用几乎相同。如您所见post_status
是publish
仅适用于岗位类型post
. 根据需要更改参数。
if ( ! is_user_logged_in() )
return print \'Nothing to see here\';
$comment_query = new WP_Comment_Query;
$comments = $comment_query->query( array (
\'status\' => \'approve\',
\'type\' => \'comment\',
// \'post_author\' => get_current_user_id(),
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'user_id\' => get_current_user_id(),
\'number\' => 20,
\'offset\' => 0,
\'order\' => \'DESC\',
\'orderby\' => \'comment_date\',
\'count\' => true,
) );
foreach ( $comments as $comment )
var_dump( $comment );