all you have to do is to add an param:
/* user commnet count */
function get_comment_count( $user_ID ) {
global $wpdb;
$count = $wpdb->get_var(
$wpdb->prepare( "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE user_id = %d ", $user_ID )
);
return $count;
}
<?php echo get_comment_count( <USER_ID> ); ?>
PS. I’ve added some proper escaping in your query also, so this code is not vulnerable any more…
But you can also use…
WordPress already has its own way of doing it, so you don’t have to reinvent the wheel… You can use:
$count = get_comments( array(
'user_id' => <USER_ID>, // include only comments by this user
'count' => true // it will return only count of comments and not the comments
) );
echo $count;
Related Posts:
- Total Word Count For Posts And Comments By One Author
- Change the Author Slug from Username to Nickname
- Change the author slug from nickname to ID
- How to let contributors to create a new revision(draft) editing their published posts
- How to limit users to one comment per post
- Display edit link if post author is current user
- Force display name as full name
- Display user’s total comment count outside The Loop
- Count user posts by type and date
- Authors Page : A page of authors
- Get all commenters on a post
- Completely hide user info
- How to edit user_id on the comment edit screen
- Users roles, make a page belonging to multiple users
- Is there any function available to echo current user’s profile url?
- the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
- Where is the information about the authors for articles stored?
- User’s total comment count excluding comments on their own posts
- Getting author page slug from get_users() or get_userdata() functions
- User capability for editing their own comments
- Delete User via Frontend
- WP users page doesn’t show users count by role
- How to force authors to ‘submit for review’?
- Create Next and Previous Link to User orderby Last Name
- How to implement friend system for WordPress?
- Custom Comment Notifications Fire on each Page Load
- Creating User Profiles using author.php
- How many members have made comments approved for an article?
- Order users by user role
- How to count total words for posts published by one author?
- How can I set wp_dropdown_users so that it shows only authors?
- get_comment_author_link not working properly
- How to auto-generate names for guest users who leave comments?
- Query posts by post type, author and post meta
- How to limit specific user ID to 5 comments per post?
- How can i display pagination in custom comment list?
- How to create page for user?
- How do I tag every author in their posts that they have made previously
- How do I change the user via SQL?
- User count only for role frontend vendor
- Add new user and user bio at same time
- show count author post today
- Link to Authors blog posts
- how to show Author post type count
- get Discussion setting in wordpress
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- How do I add a field on the Users profile? For example, country, age etc
- How to check if a user (not current user) is logged in?
- How do I display logged-in username IF logged-in?
- How to allow an user role to create a new user under a role which lower than his level only?
- user_login vs. user_nicename
- How to programatically change username (user_login)?
- Remove Ability for Other Users to View Administrator in User List?
- Difference between update_user_meta and update_user_option
- Make display name unique
- Make WooCommerce pages accessible for logged in users only
- Find out if logged in user is not subscriber
- WordPress usermeta scaling for thousands of users
- How to get WordPress Username in Array format
- Display user registration date
- Get multiple roles with get_users
- get_user_meta() doesn’t include user email?
- Confirmation required on email change
- How to Merge Two Authors Into One?
- Whats the best way to share user data across multiple WordPress websites?
- get_current_user_id() returns 0?
- Commenting in user profile page?
- How to get userid at wp_logout action hook?
- Groups of capabilities: users with multiple roles?
- Is there a way to merge two users?
- User-edit role setting distinct from wp_capabilities? [closed]
- How to Display a List of Users Who Have Made at Least 1 Post?
- List users by last name in WP_User_Query
- What’s the difference between the capability remove_users and delete_users?
- How to restrict access to uploaded files?
- Automatically delete inactive users after 2 months
- Use author author display name in permalink structure for pages and posts
- How to change user_login with wp-cli?
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- Email user when password is reset by admin
- Replacing the WordPress password validation
- Ban a user and end their session
- Allowing users to edit only their page and nobody else’s
- How can 2 blogs share the same users
- How to display a public profile page for registered users with custom slug?
- alphabetically order role drop-down selection in dashboard
- WordPress auto login after registration not working
- Execute a function when admin changes the user role
- how to use joomla password format in wordpress?
- How to do get_users() with multiple meta_keys
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Different back-end language for different users?
- Hide Admin Menu for Specific User ID who has administrator Role
- Change Comment Author Display Name
- Migrating WordPress users into Disqus
- Problem with Hebrew characters in username
- Is there an upper limit for users in WP?
- How to display the status of users (online – offline) in archive.php