Display User with the Most Comments with Count, Email, Author URL

Snippets by IsItWP

You can filter the comments in WordPress to display user with the most comments with count, email, author URL, etc.

Instructions: Add the following code to the functions.php file of your WordPress theme.
Use $result->comment_author_email, $result->comments_count, $result->comment_author_url, to add additional parameters to this code.

function top_comment_authors($amount = 5) {
global $wpdb;
$results = $wpdb->get_results('
    COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
    FROM '.$wpdb->comments.'
    WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1
    GROUP BY comment_author_email
    ORDER BY comments_count DESC, comment_author ASC
    LIMIT '.$amount
$output = "<ul>";
foreach($results as $result) {
    $output .= "<li>".$result->comment_author."</li>";
$output .= "</ul>";
echo $output;

Simply use this code in your template files to show user with most comments.

<? top_comment_authors(); ?>

You may also enjoy enabling threaded comments in WordPress.

Comments   Leave a Reply

  1. David Keulert May 12, 2012 at 1:30 am

    How can i only show the most commented user of a motnh? not all time only a month

  2. exactly i was looking for this code. you have done it for me 🙂 thanks it was helpful for my newly theme.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!