WordPress.org

Ready to get started?Download WordPress

Forums

Display multiple roles for "wp_user_query" (7 posts)

  1. KeenanPayne
    Member
    Posted 2 years ago #

    Hello,

    I want to query all authors on my blog, which span from administrator to author. I was wondering if there was any way that I could get multiple roles with a single query. Example:

    'role' => 'Administrator'

    Is there any way to include these other roles without having multiple queries?

    Thanks!

  2. typebee
    Member
    Posted 2 years ago #

    I'm no expert, but this is what I use:

    <ol>
    <?php
        $blogusers = get_users('blog_id=1&orderby=nicename');
        foreach ($blogusers as $user) {
            echo '<li>' . $user->user_nicename . '</li>';
            echo '<br />';
        }
    ?>
    </ol>

    If you don't specify any parameters for 'role', wp_user_query displays all users of your blog. Hope that helps.

  3. KeenanPayne
    Member
    Posted 2 years ago #

    Thanks for that! Unfortunately, I don't want to display all users for my blog, I want to display the following roles:

    Administrator
    Editor
    Author

    But not subscribers, as we have hundreds and the list would be too large.

    Is there any way to include multiple roles for wp_user_query?

  4. typebee
    Member
    Posted 2 years ago #

    Sorry, I don't know. You might use this nice plugin: http://wordpress.org/extend/plugins/members-list/

    After you set it up, you can 'hide' any members you don't want to show. Hiding hundreds of subscribers will take a little time, but you should have to do it only once.

    Members-List produces a nice table of members which is searchable and paginated. Hope that helps.

  5. KeenanPayne
    Member
    Posted 2 years ago #

    I think that hiding the members would be a little bit too much work, but thanks for the link to the plugin, I'll definitely have to check it out.

    Perhaps I'll just have to have three different queries for "Administrators", "Editors", and "Authors". I wanted to keep the code as minimal as possible but if that's not possible, then this is the only way I can see it working.

  6. slushman
    Member
    Posted 2 years ago #

    Hey Keenan,

    Check out this guys solution. It works for me to doing multiple queries for multiple roles.

    http://wordpress.stackexchange.com/questions/39315/get-multiple-roles-with-get-users

  7. KeenanPayne
    Member
    Posted 2 years ago #

    Awesome man, thanks a lot for that. I'm going to try that out soon and see if that works!

Topic Closed

This topic has been closed to new replies.

About this Topic