Excluding members from BP directory
-
I’ve been trying to figure this out for too long and am in desperate need to help.
Trying to exclude members from the directory depending on their S2member role (only paying members) AND whether they choose to be included (there is a custom yes/no field through which they can elect to be not listed). Seems like others must have had this set up similarly, but I can find any answers.
These two strategies look to be the most useful:
http://buddypress.org/support/topic/excluding-roles-from-the-members-directory/
http://buddydev.com/buddypress/exclude-users-from-members-directory-on-a-buddypress-based-social-network/From them I’ve cobbled together this code in functions.php.
add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user=join(',', bpdev_get_subscriber_custom_user_ids());//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are searching for friends list etc?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } function bpdev_get_subscriber_custom_user_ids(){ $users=array(); $fields = get_s2member_custom_fields($users); $findcounselor = $fields["find_a_counselor"]["user_value"]; $subscribers= get_users( array( 'role' => 's2member_level0' ,'fields'=>'ID') ); $directoryexclude= array( $findcounselor == "No",'fields'=>'ID' ) ; $users = array_merge($subscribers,$directoryexclude); return $users; }This does work with the roles….it excludes the s2member_level0 (free) users. However, I can’t get the custom field (where they click “No” to Find a Counselor) to work.
I’m by no means an experienced programmer, but I can frankenstein things together with some luck and help.
Thanks for any advice
The topic ‘Excluding members from BP directory’ is closed to new replies.