WordPress.org

Ready to get started?Download WordPress

Forums

Registered Users comment count (10 posts)

  1. junipingla
    Member
    Posted 5 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??

  2. MichaelH
    Member
    Posted 5 years ago #

    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

  3. junipingla
    Member
    Posted 5 years ago #

    Oh wow, thanks!! But where do I put this? Any advice is much appreciated!

  4. MichaelH
    Member
    Posted 5 years ago #

    I'd put it in an author template, but you mentioned your admin section and that's not something I'm too comfortable doing ;(

  5. junipingla
    Member
    Posted 5 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..

  6. MichaelH
    Member
    Posted 5 years ago #

    Wonder if something like Cimy User Extra Fields could be used and then make that code above into a function for the 'extra field'?

  7. junipingla
    Member
    Posted 5 years ago #

    I'll look into it, it would be great if it worked.

  8. 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...)

  9. 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.

  10. ericmacknight
    Member
    Posted 4 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

Topic Closed

This topic has been closed to new replies.

About this Topic