WordPress.org

Support

Support » How-To and Troubleshooting » Display multiple roles for "wp_user_query"

Display multiple roles for "wp_user_query"

  • 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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    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?

    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.

    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.

    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

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display multiple roles for "wp_user_query"’ is closed to new replies.
Skip to toolbar