WordPress.org

Ready to get started?Download WordPress

Forums

Show number of member's comments on profile? (4 posts)

  1. war59312
    Member
    Posted 8 years ago #

    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 */ ?>

    <tr>
    <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);?>
    </td>
    </tr>

    <?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,

    Will

  2. war59312
    Member
    Posted 8 years ago #

    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. :D

  3. pu2
    Member
    Posted 7 years ago #

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

  4. Xenuan
    Member
    Posted 7 years ago #

    not working :( i'm using 2.2

Topic Closed

This topic has been closed to new replies.

About this Topic