BP Profile Search › Hide certain values
-
AuthorPost
-
Alex
GuestHi 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,
Alexandrea
Plugin AuthorHi 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.
Alex
GuestHi Andrea,
Do you know how to find the type IDs of the member type?
Thanks,
Alexandrea
Plugin AuthorYes, 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.
Alex
GuestHi 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,
Alexandrea
Plugin AuthorHi 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">
Alex
GuestHi Andrea,
That worked, thanks again for the great support.
Alex
andrea
Plugin AuthorGreat, you’re welcome!
-
AuthorPost