I have this query so far :

        $user_args = array(
            'role'    => 'frontend_vendor',
            'orderby' => 'display_name', 
            'order'   => 'ASC',      
            'number'  => $no,
            'offset'  => $offset

        $user_query = new WP_User_Query( $user_args );

Now what I want to do is to get all users that has only posts, i have an example query that i want to do. how do i do this with wp_query()?

SELECT users.id, posts.id 
FROM wp_users 
RIGHT JOIN wp_posts 
ON wp_users.id = wp_posts.user_id 
WHERE wp_posts.post_type = 'downloads'
AND wp_users.role = 'frontend_vendor' 
ORDER BY display_name 

If the user has no posts, he should not be selected.

2 Answers 2


add this in your arguments 'query_id' => 'authors_with_posts',

    $user_args = array(
        'role'    => 'frontend_vendor',
        'orderby' => 'display_name', 
        'query_id' => 'authors_with_posts',
        'order'   => 'ASC',      
        'number'  => $no,
        'offset'  => $offset
  • I just tried this, it works! its so simple! Sep 17, 2015 at 0:23

Here are below some possible options:

codex link

Order & Orderby Parameters we can add post_count otherwise there is no such parameter such as "posts_per_author" does not exist in wp_query refrence

please include orderby in your query

'orderby' => 'post_count'

FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) LEFT OUTER JOIN (
            SELECT post_author, COUNT(*) as post_count
            FROM wp_posts
            WHERE post_type = 'post' AND (post_status = 'publish' OR post_status = 'private')
            GROUP BY post_author
        ) p ON (wp_users.ID = p.post_author)

Use count in code according to requirement.

Get Authors or users

<?php $list = wp_list_authors('show_fullname=1&optioncount=1&orderby=post_count&order=DESC&number=3'); ?>
<?php echo"<pre>";   print_r($list); echo"</pre>"; ?>

"optioncount" can help in this case.

with direct query please see this post:

Get users with atleast one post


  • hi thanks for a quick reply. but how do i do it with using wordpres wp_query? get all users that has only posts Sep 16, 2015 at 10:10
  • i have tried this wp_list_authors('show_fullname=1&optioncount=1&orderby=post_count&order=DESC&number=3'); but returns null Sep 16, 2015 at 10:10
  • I have updated answer, please check and as well please go thorough codex link mentioned in answer to see parameters.
    – jas
    Sep 16, 2015 at 10:13
  • i tried this wp_list_authors no results, just plain white. is there somethings that i should change on the paramets? Sep 16, 2015 at 10:26
  • please make sure that you have users with some added posts, I ca assure you that I am getting list with username and post count in brackets. codex.wordpress.org/Function_Reference/wp_list_authors
    – jas
    Sep 16, 2015 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.