Add link to reset search filters

Hey @everyone,

I stumbled upon this old Feature Request and wanted to try implementing it myself. The following snippet seems to be working for me as a temporary workaround.

How to use:

  1. Add the following PHP snippet to you site via a plugin like Code Snippets
  2. replace /search/ in the code snippet, if your search page URL is different.
  3. Save the snippet and check your Filter section on your main listings page.
add_filter(
	'hivepress/v1/forms/listing_filter',
	function( $form ) {
		$form['footer'] = isset( $form['footer'] ) ? $form['footer'] : '';
		$form['footer'] .= '<div id="reset-filters" style="text-align: center; margin-top: 15px;"><a class="hp-link" title="Reset Search Filters" href="/search/"><i class="hp-icon fas fa-redo"></i> Reset Filters</a></div>';
		return $form;
	},
	1000
);

Result:

image
(Pre styled as a typical HivePress link/button with a sensible icon chosen, too. :slight_smile: )

Note: the snippet does not actually reset the applied filters, it simply links to your base search page, which in my case is /search/ - Hence, you might need to update the snippet depending on your URL and site structure.

I don’t personally use a vendor search page, but if you do, updating listing_filter to vendor_filter as suggested earlier in the topic should work for you.

I hope this helps!

Cheers,
Chris :victory_hand: