Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Sort by Role (4 posts)

Started 1 year, 10 months ago by: Creative Slice

  • Profile picture of Creative Slice Creative Slice said 1 year, 10 months ago:

    Is there a way to show a member list by role? So members who have the role “editor” would show up in a member list? This would probably be a modification of:

    if ( bp_has_members( ‘type=active&max=20& —> USER TYPE = EDITOR <— ' ) ) :

    Thanks in advance for any help.

  • Profile picture of Lance Willett Lance Willett said 1 year, 10 months ago:

    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.

  • Profile picture of Creative Slice Creative Slice said 1 year, 10 months ago:

    Thanks for the tip Lance. I ended up doing it this way with “s2member_level4″ as the custom role:

    http://bpdev.pastebin.com/0whWjpvx

  • Profile picture of Tammy Hart Tammy Hart said 1 year ago:

    AWEsome! thank you so much for that code!