I would like to see the number of comments entered by the user connected ( $user_id = get_current_user_id();
). I have tried this code but it does not work.
<?php
global $wpdb, $post, $current_user;
get_currentuserinfo();
$userId = $current_user->ID;
$where = 'WHERE comment_approved = 1 AND user_id = ' . $userId ;
$comment_count = $wpdb->get_var("SELECT COUNT( * ) AS total
FROM {$wpdb->comments}
{$where}");
echo $comment_count;
?>
Do you have any advice? What am I doing wrong? Thank you.