I’ve got some code like this:
$query_args = array(); $query_args['fields'] = array( 'ID', 'display_name' ); $query_args['role'] = 'subscriber'; $users = get_users( $query_args ); foreach ($users as $user) $users_array[$user->ID] = $user->display_name;
I want to get more roles and also include contributor
, author
and some custom roles I created with the Role Scoper plugin e.g. Manager
, etc. Any ideas how I can do this with get_users
?
Thanks
9 s
Fastforward to WordPress 4.4 – it will support the role__in
attribute!
It looks like WordPress 4.4 is our lucky version number, because it will support both the role__in
and role__not_in
attributes of the WP_User_Query
class.
So to include the subscriber, contributor and author roles, we can simply use:
$users = get_users( [ 'role__in' => [ 'subscriber', 'subscriber', 'author' ] ] );
Check out the ticket #22212 for the whole story!