Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yellowberri-snippets/6499650 to your computer and use it in GitHub Desktop.
Save yellowberri-snippets/6499650 to your computer and use it in GitHub Desktop.
PHP: WP: Get All Users from Certain Roles
// Get all users from multiple roles
// http://wordpress.stackexchange.com/questions/39315/get-multiple-roles-with-get-users
function get_authors() {
$users = array();
// List these in heirarchical order
$roles = array('editor', 'author', 'contributor');
foreach ($roles as $role) :
$users_query = new WP_User_Query( array(
'fields' => 'all_with_meta',
'role' => $role,
'orderby' => 'post_count',
'order' => 'DESC',
'orderby' => 'display_name'
) );
$results = $users_query->get_results();
if ($results) $users = array_merge($users, $results);
endforeach;
return $users;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment