Jay
Jay

Reputation: 3

How to set get_users = multi roles?

I'm new to WP codex can you help me guys on how can i make this multiple roles instead of subscribers only?

$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber');

Upvotes: 0

Views: 2573

Answers (3)

Kangulo
Kangulo

Reputation: 41

you can use role__in argument.

Example:

$args = array( 
    'role__in' => array('administrator','shop_manager'),
    'fields' => 'all',
);
$users = get_users($args);

Upvotes: 2

Gavin Simpson
Gavin Simpson

Reputation: 2832

2021 Update. As per https://wordpress.stackexchange.com/questions/211916/show-all-author-products-from-specific-category

I am putting this here as the question was more relevant on google results for what I was lookin for.

author__in (array) - use author id (available since Version 3.7).

eg

$roles=array('administrator','shop_manager');
$args = array(
            'role__in'    => $roles,
    );
$users = get_users($args);

Upvotes: 1

Ali Idrees
Ali Idrees

Reputation: 598

$roles = array('subscriber', 'custom_role1', 'custom_role2');
$users = array();
foreach($roles as $role){
    $args = array(
                 'blog_id' => 1,
                 'orderby' => 'nicename',
                 'role' => $role
                 );
    $current_role_users = get_users($args);
    $users = array_merge($current_role_users, $users);
}

Upvotes: 2

Related Questions