wordpress调用显示当前登录用户评论数量
博客吧在制作wordpress前台会员中心时,需要在会员中心主页展示当前登录用户的评论数量,因此检索了wordpress相关函数,发现通过get_comments()函数即可轻松获取登录用户的评论数,下面是获取的完整代码。
方法一:
通过get_comments()函数获取
1 2 3 4 | <?php global $user_ID; echo get_comments('count=true&user_id='.$user_ID); ?> |
方法二:
通过$wpdb查询数据库获取
1 2 3 4 5 6 7 | <?php global $wpdb,$user_ID; $count_user_comments = $wpdb->get_var( $wpdb->prepare("Select count(comment_ID) from $wpdb->comments where user_id = %d", $user_ID) ); echo $count_user_comments[0]; ?> |
以上两种方法输入的结果都是当前已登录用户的总评论数量。
除非注明,文章均由 博客吧 整理发布,欢迎转载。
转载请注明本文地址:https://www.boke8.net/wordpress-current-user-comments.html
如果喜欢,可以:点此订阅本站
发表留言