Restricting location to specific categories also removes it from the search bar

I used this snippet from GitHub to set the location field for specific categories only, but this also removes it from the search bar by default because no category is selected (like on the homepage).

Is there a way to customize the snippet so it only applies to the Add/Update Listing pages and the admin area? Or do you have a snippet to add it back to the search bar?

Thank you!

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['location'] ) ) {
			$categories = [ 1, 2, 3 ];

			$attributes['location']['categories']  = $categories;
			$attributes['latitude']['categories']  = $categories;
			$attributes['longitude']['categories'] = $categories;
		}

		return $attributes;
	},
	1000
);

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation. Also, please note that if location remains in the global form, even when these categories are not selected, then listings without location (those outside these categories) will simply disappear from the search when searching by location, so the location field is displayed only for selected categories.

Okay, thanks for your reply!

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