Comment Count for each Comment Author

Place this in your functions.php theme file:

<?php
function ps_count_user_comments() {
    global $wpdb;
    $count = $wpdb->get_var(
    'SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' 
    WHERE comment_author_email = "' . get_comment_author_email() . '" 
    AND comment_approved = "1" 
    AND comment_type IN ("comment", "")'
    );

    return $count . ' comments';
}
?>

This code will count the author comments and do NOT include Trackbacks/Pingbacks.

Then You print it like this:

<?php echo ps_count_user_comments(); ?>

You can try to run this in your SQL and change [email protected] to your mail. I assume your database prefix is wp_ but if its not, just change wp_comments to your prefix.

SELECT COUNT(comment_ID) FROM wp_comments 
WHERE comment_author_email = "[email protected]"  
AND comment_approved = "1" 
AND comment_type IN ("comment", "")

Leave a Comment