admin管理员组文章数量:1126119
There doesn't seem to be an easy WP way to show the total number of different commenters, just total # of comments.
Is there a better than manually loop through all comments and counting the unique user ID's?
There doesn't seem to be an easy WP way to show the total number of different commenters, just total # of comments.
Is there a better than manually loop through all comments and counting the unique user ID's?
Share Improve this question asked Nov 16, 2014 at 3:38 jetlejjetlej 5721 gold badge6 silver badges24 bronze badges1 Answer
Reset to default 2You could try to count the number of unique comment author emails per post:
/**
* Number of unique comment author emails per post:
*
* @see http://wordpress.stackexchange.com/a/168606/26350
* @param int $pid
* @return int
*/
function get_unique_commenters_by_post_id( $post_id )
{
global $wpdb;
$sql = "SELECT COUNT(1) as uc FROM (
SELECT COUNT(1) as c FROM {$wpdb->comments}
WHERE comment_post_ID = %d
GROUP BY comment_author_email
) as t";
return $wpdb->get_var( $wpdb->prepare( $sql, $post_id ) );
}
Usage example:
echo get_unique_commenters_by_post_id( $post_id = 213 );
本文标签: commentsWay to count the number of people who have commented on a post
版权声明:本文标题:comments - Way to count the number of people who have commented on a post? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736681549a1947447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论