Make a location attribute indexable

Hi,

I understand that HivePress uses the excerpt field in Wordpress as a search snippet, and that if I mark an attribute as ‘indexable’ then it feeds through into this snippet.

I’d like to include Location in the search snippet, but even when I mark the Location attribute as indexable, it doesn’t feed through.

As I say, I have Location listed as an attribute, but I’m not 100% sure this is what HivePress is using or whether I added it and it’s actually unused.

I’m also using MapBox for geolocation, if that’s relevant.

The reason I want to add location is because the search snippet can pull through to Mailerlite, and I can then include it in weekly email roundups.

Thanks
Adam

Hi,

Please send us the snippet you are using and we will review it in more detail.

Thanks for your reply. I’m not using a snippet (apologies for not being clear about that), I’m referring to the ‘search snippet’ that you explain here:

So the question is, can I make Location appear within the job listing excerpt / ‘search snippet’?

Hi,

Sure, please use this PHP snippet:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['location'] ) ) {
			$attributes['location']['indexable'] = true;
		}

		return $attributes;
	},
	1000
);

You can add a PHP snippet using this doc: How to add custom code snippets - HivePress Help Center

​I hope this is helpful to you

1 Like

Perfect! Thank you for your help.

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