Support » Fixing WordPress » Users Comments Count (author.php)

  • Hi,

    I am creating a wordpress site in which users participate both by posting items like comments, they will have a profile page (autor.php) where I want to show the number of comments posted by the user. I found this code:

    < ?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 . '
    ';
    }
    ? >

    The problem is that he shows me a list of all users who have posted a comment, when what interests me is showing the number of comments that have published the user being displayed at that time (in the progile). I’ve tried to change with different variables of WP, but I cant find the solution

    Thanks!
    Greetings!

  • The topic ‘Users Comments Count (author.php)’ is closed to new replies.