Support » Plugins and Hacks » Show number of member’s comments on profile?

Show number of member’s comments on profile?

  • Hello,

    First off, I am not a programmer so just trying to figure it out. 😉

    Anyways, I am trying to display on a member’s profile page in the adminCP their total number of comments.

    I just can not figure out how to do it. 🙁

    Well here is what I have at the moment. But it only displays the first result, which is the first member, me, so the number will always be the total amount of my comments not the selected users.

    So basically in the sql query I only want to grab the total number of comments for the selected user but I don’t know how to grab that number only for the selected user so at the moment it grabs them for all.

    Well any help on this would be great.

    <?php /* Start Number of Member's Comments Hack */ ?>

    <th scope="row"><?php _e('Comments:') ?></th>
    <td><?php function get_number_of_user_comments($user_comment_id) { global $wpdb, $userCommentCount; $user_comment_id = (int) $user_comment_id; $userCommentCount[$user_comment_id] = $wpdb->get_var("SELECT COUNT( * ) AS 'Number of Comments' FROM $wpdb->comments, $wpdb->users WHERE $wpdb->comments.user_id = $wpdb->users.ID GROUP BY ID ORDER BY 'User Name' ASC"); return apply_filters('get_number_of_user_comments', $userCommentCount[$user_comment_id]);} echo get_number_of_user_comments($edituser->ID);?>

    <?php /* End Number of Member's Comments Hack */ ?>

    Now I know to display the selected user’s total amount of comments the where clause would be like this for example, for member number 14:

    WHERE $wpdb->comments.user_id = $wpdb->users.ID AND $wpdb->comments.user_id = '14'

    I just don’t know how to get the user_id of the selected member. So instead of the 14 it would be the selected member. That is the member’s whos profile your viewing.

    Thanks a lot for your help,


Viewing 3 replies - 1 through 3 (of 3 total)
  • OMG, damn I always make things way to complicated.

    I finally figured it out, simply:

    <?php $userID = ($edituser->ID); $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE $wpdb->comments.user_id='$userID'"); echo $totalcomments; ?>

    hehe I always do that. 🙂 But what makes me great, is that I never give up. 😀

    Hey, this is what I want too, but I only get the output “59” disregarding which account I’m logged in with. I have more than 59 comments in total on the blog, so it can’t be it shows total number of comments, and the accounts I use to login are nowhere near 59 comments..

    not working 🙁 i’m using 2.2

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show number of member’s comments on profile?’ is closed to new replies.