这里我为您编写了一个基于SQL的函数-
function the_dramatist_count_user_comments( $args = array() ) {
global $wpdb;
$default_args = array(
\'author_id\' => 1,
\'approved\' => 1
);
$param = wp_parse_args( $args, $default_args );
$sql = $wpdb->prepare( "SELECT COUNT(comments.comment_ID)
FROM {$wpdb->comments} AS comments
LEFT JOIN {$wpdb->posts} AS posts
ON comments.comment_post_ID = posts.ID
WHERE posts.post_author = %d
AND comment_approved = %d
AND comment_type IN (\'comment\', \'\')",
$param
);
return $wpdb->get_var( $sql );
}
使用方法如下-
$author_posts_comments_count = the_dramatist_count_user_comments(
array(
\'author_id\' => 1, // Author ID
\'approved\' => 1, // Approved or not Approved
)
);
现在开始
$author_posts_comments_count
您将获得作者所有帖子的完整评论计数。
它经过测试。
希望这有帮助。