Taxonomy Search

Thanks to Mark Haygen and Tracy Haygen for letting me test this feature on their site CrewCall.community. The site won’t be ready for live use until June 2021.

If you are using BuddyPress Xprofile Custom Field Types and wish to search a Custom Taxonomy Multiselector field, you need to register that field type with BP Profile Search before you can add it to your search forms.

To do that, add this code to your bp-custom.php:

use BPXProfileCFTR\Field_Types\Field_Type_Multi_Select_Taxonomy;

add_action ('bps_custom_field', 'bps_register_msct');
add_action ('bp_ps_custom_field', 'bps_register_msct');
function bps_register_msct ($f)
{
	if ($f->type != 'multiselect_custom_taxonomy')  return;

	$taxonomy = Field_Type_Multi_Select_Taxonomy::get_selected_taxonomy ($f->id);
	$terms = get_terms ($taxonomy, array ('hide_empty' => false));

	$f->format = 'set';
	foreach ($terms as $t)
		$f->options[$t->term_id] = $t->name;
}

add_action ('bps_field_before_search_form', 'bps_change_display');
add_action ('bp_ps_field_before_search_form', 'bps_change_display');
function bps_change_display ($f)
{
	if (isset ($f->type) && $f->type == 'multiselect_custom_taxonomy')
		$f->display = 'multiselectbox';
}

A general explanation on how to register custom field types is in:

Custom profile field types