Hide certain values

BP Profile Search Hide certain values

  • Author
    Post
  • #11906 Reply
    Alex
    Guest

    Hi Andrea,

    I’m doing a search on member type and I want to be able to hide certain types, for example I have an “Admin” type which I don’t want to show in the search options.

    Thanks,
    Alex

    #11908 Reply
    andrea
    Plugin Author

    Hi Alex,

    To hide a few options in a Member type search field, you can add this code to your bp-custom.php file:

    add_action ('bps_field_before_search_form', 'hide_options');
    function hide_options ($f)
    {
    	if ($f->code == 'bp_member_type')
    	{
    		unset ($f->options[19]);
    		unset ($f->options[34]);
    		...
    	}
    }
    

    Replace 19, 34 and so on with the actual type IDs of the member types you want to hide.

    #11909 Reply
    Alex
    Guest

    Hi Andrea,

    Do you know how to find the type IDs of the member type?

    Thanks,
    Alex

    #11910 Reply
    andrea
    Plugin Author

    Yes, use the Inspect function of your browser to see the HTML code of the existing search field options.

    In Chrome, go to a page where your search form is displayed, hover on the Member type field, right-click and select Inspect.

    #11911 Reply
    Alex
    Guest

    Hi Andrea,

    I appreciate all this help but that doesn’t work.

    I want to remove “Admin” and when I inspect that field all I get is this “<input type=”checkbox” name=”field_4_one_of[]” value=”admin”>”.

    There is no id there, I even looked in the database and it has an id of “21”. I put that in the code you sent and it doesn’t do anything.

    Thanks,
    Alex

    #11912 Reply
    andrea
    Plugin Author

    Hi Alex,

    I see you are not using the BuddyPress member type, but a profile field (field_4). So in your case the code is:

    add_action ('bps_field_before_search_form', 'hide_options');
    function hide_options ($f)
    {
    	if ($f->code == 'field_4')
    	{
    		unset ($f->options['admin']);
    		...
    	}
    }
    

    In the above code, ‘admin’ comes from the value="admin" attribute of your checkbox:

    <input type="checkbox" name="field_4_one_of[]" value="admin">
    
    #11913 Reply
    Alex
    Guest

    Hi Andrea,

    That worked, thanks again for the great support.

    Alex

    #11914 Reply
    andrea
    Plugin Author

    Great, you’re welcome!

Reply to: Hide certain values
My Information