BuddyDev

Search

[Resolved] Hide Members based on Member Type?

  • Participant
    Level: Initiated
    Posts: 5
    Kenny Larsen on #2438

    Hi,

    Firstly thanks for the great plugins and site – you’ve saved me countless hours.

    I’m currently using the code here – https://buddydev.com/buddypress/hiding-users-on-buddypress-based-site/

    which works for hiding users by id or role, but is there a way to do it based on member type instead?

    Thanks, Kenny

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #2439

    Hi Kenny,
    Welcome to BuddyDev forums.

    Please use the following code

    
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_member_type' );
     
    function buddydev_exclude_users_by_member_type( $args ) {
        //do not exclude in admin
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
        
        $excluded_member_type = isset( $args['member_type__not_in'] )? $args['member_type__not_in'] : array();
     
        if ( ! is_array( $excluded_member_type ) ) {
            $excluded_member_type = explode(',', $excluded_member_type );
        }
        
    	//member types to exclude, change it
    	$types_to_exclude = array( 'student', 'teacher' );//add your own list
        
        $excluded_member_type = array_merge( $excluded_member_type, $types_to_exclude );
        
        $args['member_type__not_in'] = $excluded_member_type;
        
        return $args;
    }
    
    

    You can specify one or more member type by their unique name in $types_to_exclude array.

    Please let me know if that works or not?

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #2442

    Hi Kenny,
    Marking this topic as resolved a per email. The code works.

    In future, if you are unable to post reply, please try refreshing the browser and you will be shown as properly logged in. It happens sometimes due to caching.

    Thank you
    Brajesh

The topic ‘ [Resolved] Hide Members based on Member Type?’ is closed to new replies.

This topic is: resolved