Hi damland,
BP Profile Search maintains one active search for each Members directory. When the current page is a Members directory, the code:
$request = bps_get_request ('filters');
provides the active search for the current directory, otherwise an empty array.
The function bps_get_request() is in bps-search.php.
Thread Starter
DAM
(@damland)
@dontdream Thanks!
Using bps_form=clear I can remove all the filters, but is there an easy way to remove only one filter and keep the others active?
Yes, you could use the ‘bps_request’ hook, and unset the filter(s) you don’t need. For instance:
add_filter ('bps_request', 'clear_filter', 10, 3);
function clear_filter ($request, $type, $form)
{
unset ($request['field_4_contains']);
return $request;
}
Thread Starter
DAM
(@damland)
@dontdream I need to put a button for each filter to remove that filter (one by one), what’s the best way to use bps_request to unset them? thanks
Hi damland,
I have that feature in my to-do list, but I haven’t found the time to design it yet.
Probably the best way is to use AJAX and set the ‘bps_request’ cookie value with the remaining array of filters, whenever the user hits an individual clear-filter button.
Thread Starter
DAM
(@damland)
Why don’t use WP REST API to update the results without refresh the page?
I’m not very familiar with the WP REST API yet, so I’m not sure. BuddyPress 5.0.0 will ship with the BP REST API, and that could be taken into consideration too.