I want to get the users of role academic and student. I have tried using the code below (passing an array of roles, but all users are being displayed, so clearly it’s not working.
$roles=array('academic','student');
$args =array('role'=>$roles);
$users=get_users( $args );
foreach ($users as $user) {
echo '<li>' . $user->user_email . '</li>';
}
I don’t think it’s possible to do it with the get_users function. From what the Codex implies, you cannot pass arrays to the role argument. But it should be fairly easy to code your way out of that limitation.
Try this:
Asking for users with the argument field=all_with_meta is very powerful, and WP seems to map indexes which aren’t even shown when doing a print_r on the user object. That is why we can sort them using first or last names, as shown above (I actually took the code from an older answer of mine).
Let us know how it goes?
loop through the roles and merge the results…
this will work with any number of roles.