开发者

Wordpress - Total User Count who only have posts

开发者 https://www.devze.com 2022-12-29 17:00 出处:网络
I want to display total number of user who only have posts at Wordpress. I can get all users by this query

I want to display total number of user who only have posts at Wordpress. I can get all users by this query

<?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;"); echo $user_count ?>

But for the user count only with posts, i think i might need to join another table, does anyone have snipp开发者_运维百科ets ? Thanks.


I don't use wordpress, but if the schema at http://codex.wordpress.org/images/8/83/WP_27_dbsERD.png is close to the version that you are using, then you should be able to do something like

SELECT COUNT(*) FROM wp_posts GROUP BY post_author 

If you wanted to know which users had what number of posts you could do

SELECT COUNT(*) AS number_of_posts, u.user_login FROM 
wp_user u, wp_post p WHERE u.ID = p.post_author HAVING number_of_posts > 0;
0

精彩评论

暂无评论...
验证码 换一张
取 消