Skip to content

Instantly share code, notes, and snippets.

@Tsunamijaan
Created January 5, 2019 09:13
Show Gist options
  • Select an option

  • Save Tsunamijaan/e41ef134ad9a235a5b35a2735470c37f to your computer and use it in GitHub Desktop.

Select an option

Save Tsunamijaan/e41ef134ad9a235a5b35a2735470c37f to your computer and use it in GitHub Desktop.
Get top commenter author
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;
}
How To use:===========
<? top_comment_authors(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment