Remove Location from Search Field and add it to Filters

Hi there,
I want to remove the location from the search (managed to do so via the snippet below) and want to have it as a normal filter on the left instead. How can I add that filter?

add_filter(
	'hivepress/v1/forms/listing_search',
	function( $form ) {
		unset($form['fields']['location']);

		return $form;
	},
	1000
);

I tried this but it does not work:

add_filter(
'hivepress/v1/forms/listing_filter',
	function($form){
		set($form['fields']['location']);
		
		return $form;
	},
	1000
);
1 Like

Hi,

Please try this hook: hivepress/v1/models/listing/attributes and set the location attribute to searchable=false and filterable=true, and everything should work correctly.

Amazing, thanks. I got it to work with the snippet below.

//Listing Description Optional

add_filter(
	'hivepress/v1/models/listing/attributes',
	
		function( $attributes ) {
		if ( isset( $attributes['location'] ) ) {
			$attributes['location']['filterable'] = true;
			$attributes['location']['searchable'] = false;	
		}
 
		return $attributes;
	},
1000
);

add_filter(
	'hivepress/v1/forms/listing_filter',
	function($form){
		if(isset($form['fields']['location'])){
			$form['fields']['location']['_order'] = 200;
			$form['fields']['location']['description'] = 'Solo si quieres la modalidad presencial';						
			$form['fields']['location']['label'] = 'Ubicacion';			
		}
		
		return $form;
	},
	1000
);

Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.