junipingla
Member
Posted 4 years ago #
I've been searching for so long for a plugin or hack or function that let's me see how many comments a registered user has made.
I'm running a personal blog (plugin members only) and I would like to be able to easily have listed how many comments a user has made, perhaps listed in the users.php in the Admin panel.
Could anyone direct med to a solution??
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
junipingla
Member
Posted 4 years ago #
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 ;(
junipingla
Member
Posted 4 years ago #
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'?
junipingla
Member
Posted 4 years ago #
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.
ericmacknight
Member
Posted 3 years ago #
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