Home / author / Display user with the most comments with count, email, author url
  • How to Display user with the most comments with count, email, author url

    display-user-with-the-most-comments

    Adding this snippet to the functions.php of your wordpress theme will let you display the top commenter list of users. Use $result->comment_author_email, $result->comments_count, $result->comment_author_url, to add additional parameters to this snippet.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    function top_comment_authors($amount = 5) {
    global $wpdb;
    $results = $wpdb->get_results('
        SELECT
        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;
    }
    
    ( click code to copy )

    wordpress snippet : PHP - template

    <>
    <? top_comment_authors(); ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    template, author_email, comment_author, _e, wp,
  • exactly i was looking for this code. you have done it for me :) thanks it was helpful for my newly theme.

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