Does anyone know if the function get_users
supports an array of user roles? My guess is that it doesn’t.
I have the following which works:
$args =array(
'role' => 'line_manager'
);
$blogusers = get_users($args);
foreach ($blogusers as $user) {
I then adapt the above to look like the following and it returns empty.
$args =array(
'role' => array('line_manager','administrator')
);
$blogusers = get_users($args);
foreach ($blogusers as $user) {
If it doesn’t support arrays, is there a workaround other than doing a wp_query
?
Yes, you’re right, it doesn’t support arrays.
That’s a string to be used in the SQL query
LIKE '%"line_manager"%'
.But a simple
array_merge
can solve this:You could also use the action hook
pre_user_query
, but it seems overkill.As @brasofilo said you essentially need to build separate queries and combine the results. Here’s an alternative and slightly shorter {example} way to do it -assuming you want to just collect ID’s: