Simply paste the following code where you'd like the count to be displayed. Re-arrange the code as desired.
<?php
global $wpdb;
$where = 'WHERE comment_approved = 1 AND user_id <> 0';
$comment_counts = (array) $wpdb->get_results("
SELECT user_id, COUNT( * ) AS total
FROM {$wpdb->comments}
{$where}
GROUP BY user_id
", object);
foreach ( $comment_counts as $count ) {
$user = get_userdata($count->user_id);
echo 'User ' . $user->display_name . ' comment count is ' . $count->total . '
';
}
?>
Credits: Michael H on WordPress forums.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
Display registered users comment count on your WordPress blog
Display registered users comment count on your WordPress blog
by Jean-Baptiste Jung on October 19, 2009
Simply paste the following code where you'd like the count to be displayed. Re-arrange the code as desired.
<?php global $wpdb; $where = 'WHERE comment_approved = 1 AND user_id <> 0'; $comment_counts = (array) $wpdb->get_results(" SELECT user_id, COUNT( * ) AS total FROM {$wpdb->comments} {$where} GROUP BY user_id ", object); foreach ( $comment_counts as $count ) { $user = get_userdata($count->user_id); echo 'User ' . $user->display_name . ' comment count is ' . $count->total . ' '; } ?>Credits: Michael H on WordPress forums.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
Display registered users comment count on your WordPress blog