This will get approved comment count for each registered user
<?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 "<pre>"; print_r($count); echo "</pre>";
//echo "<pre>"; print_r($user); echo "</pre>";
echo 'User ' . $user->display_name . ' comment count is ' . $count->total . '
';
}
?>
used wp-includes/comment.php ‘get_comment_count’ as example
Oh wow, thanks!! But where do I put this? Any advice is much appreciated!
I’d put it in an author template, but you mentioned your admin section and that’s not something I’m too comfortable doing ;(
OK Michael!
I would like to easily see which users that rarely or never comment, that’s why I would like to have it listed in the Userlist..
Wonder if something like Cimy User Extra Fields could be used and then make that code above into a function for the ‘extra field’?
I’ll look into it, it would be great if it worked.
Has anyone had a chance to look into this?
I’d like that as well (actually I’d like to add fields to the users.php list, including that…)
Okay, I found a way to incorporate this into a half-assed recently-registered plugin I’m working on, but I can’t update it since SVN is broken on my new machine. Heh.
MichaelH,
How can I modify your code above to generate a list that looks like this:
Alice (3)
Bob (4)
Carl (7)
David (5)
Many thanks!
Eric