Query All users that has post

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 
ASC
LIMT 8
OFFEST 0

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
    );

Leave a Comment