Skip to content

Instantly share code, notes, and snippets.

Last active March 30, 2021 16:47
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Hide Subscriber Users from BuddyPress member Directory
function bpdev_exclude_users($qs=false,$object=false){
//list of users to exclude
if($object!='members')//hide for members only
return $qs;
$excluded_user=join(',',bpdev_get_subscriber_user_ids());//comma separated ids of users whom you want to exclude
//check if we are searching for friends list etc?, do not exclude in this case
return $qs;
return $qs;
function bpdev_get_subscriber_user_ids(){
$subscribers= get_users( array( 'role' => 'subscriber', 'fields' => 'ID' ) );
return $users;
Copy link

Super late reply, but for @Hastibe and anyone else who wants to exclude all but one role, change the exclude to include.

// Helper for fetching all IDs to include. Returns an array in this example.
$included_user_ids = my_function_to_fetch_all_users_by_role();

$args = wp_parse_args( $qs );
$args['include'] = implode( ',', $included_user_ids );

$qs = build_query( $args );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment