Skip to content

Instantly share code, notes, and snippets.

@webmasterninjay
Created January 21, 2020 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmasterninjay/de4841cb689d1085bfeb684354d03bab to your computer and use it in GitHub Desktop.
Save webmasterninjay/de4841cb689d1085bfeb684354d03bab to your computer and use it in GitHub Desktop.
Exclude several user roles from buddypress loop
<?php
function exclude_roles_from_members_loop( $retval ) {
if ( bp_is_members_directory() ) {
$exclude_ids = get_users(
array(
'fields' => 'ID',
'role__in' => array( 'editor', 'author' ) // change the roles here
)
);
$retval['exclude'] = $exclude_ids;
}
return $retval;
}
add_filter( 'bp_before_has_members_parse_args', 'exclude_roles_from_members_loop' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment