WordPress – Total User Count who only have posts

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 snippets ? Thanks.

Related posts

Leave a Reply

1 comment

  1. 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;