X

How to display a user’s total comment count on WordPress

Put below code to your template and it will display the total comment count of user.

 
<?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 'Comments: <strong>' . $comment_count . '</strong>';
 
?>