Created
September 9, 2013 18:34
-
-
Save yellowberri-snippets/6499650 to your computer and use it in GitHub Desktop.
PHP: WP: Get All Users from Certain Roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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