admin管理员组文章数量:1391969
hi i want to show author comment count in author page. this code can display current user comment count but i dont want current user i need any user please help me
/* user commnet count */
function commentCount() {
global $wpdb, $current_user;
get_currentuserinfo();
$userId = $current_user->ID;
$count = $wpdb->get_var('
SELECT COUNT(comment_ID)
FROM ' . $wpdb->comments. '
WHERE user_id = "' . $userId . '"');
echo 'Şərh sayı ' . $count ;
}
<?php commentCount(); ?>
hi i want to show author comment count in author page. this code can display current user comment count but i dont want current user i need any user please help me
/* user commnet count */
function commentCount() {
global $wpdb, $current_user;
get_currentuserinfo();
$userId = $current_user->ID;
$count = $wpdb->get_var('
SELECT COUNT(comment_ID)
FROM ' . $wpdb->comments. '
WHERE user_id = "' . $userId . '"');
echo 'Şərh sayı ' . $count ;
}
<?php commentCount(); ?>
Share
Improve this question
asked Feb 19, 2020 at 9:10
Gidromasservis QSCGidromasservis QSC
331 silver badge10 bronze badges
1 Answer
Reset to default 1all 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;
本文标签: usersAuthor comment count in author page
版权声明:本文标题:users - Author comment count in author page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744736341a2622351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论