Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Sort by Role


Lance Willett
Participant

@lancewillett

Why not just use a group for this?

There isn’t a way to do this in BuddyPress without writing your own code to do it. You could use WP_User_Search to look up users, it is defined in /wp-admin/includes/user.php starting near line 637.

Here’s an example from http://www.clarksonenergyhomes.com/wordpress/2009/03/16/wp-get-users-by-role-function/ (found via Google).


function get_users_with_role ( $role ) {
// gets all users with specified role
$wp_user_search = new WP_User_Search( '', '', $role );
return $wp_user_search->get_results();
}

This type of user search is intended for use in Administration Panels, not on public-facing pages. So be sure you know why you’re exposing that information before you do it. I’d urge against ever showing a member’s user role publicly. It’d probably be much better to use a Group for those users and display them that way — based on their membership in a certain group instead of their user role.

Skip to toolbar