[wp-hackers] function to show total comments by user

danilo danixland at gmail.com
Sun Jan 16 21:13:00 UTC 2011

> On the other hand, it might be better to simply build a custom SQL query to
> get the count, rather than grabbing all the author's comments but not using
> them.
> function comment_author_comments_count($comment_author_email) {
>      global $wpdb;
>      echo $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) AS total
> FROM {$wpdb->comments} WHERE comment_author_email = %s",
> $comment_author_email );
> }
> The second method will be MUCH more space/time efficient than the first.
Thanks, that's exactly what I was looking for.. it worked like a charm, 
you just forgot a closing bracket for the get_var(). ;)
In the comments.php file I used get_comment_author_email() and it worked 

Thanks a lot again!!
Danilo aka danix

More information about the wp-hackers mailing list