在开发WordPress主题用户中心时想获取到当前已登录用户的文章数量和评论数量,自己一时没想出解决方法。
于是百度搜了搜,发现几行代码就能搞定,于是记录下来。
//当前登录用户 get_current_user_id(); // 或者 global $user_id;
//文章数量 count_user_posts($user_id )
//评论数量 global $wpdb; $count_user_comments = $wpdb->get_var( $wpdb->prepare(\"Select count(comment_ID) from $wpdb->comments where user_id = %d\", $user_id) ); var_dump($count_user_comments);
标签:
本文链接:https://www.xiaba.cc/html/2075.html
版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!