Skip to content

Im Trying To

Michael Beckwith edited this page Mar 17, 2023 · 13 revisions

Customize Autocomplete

Customize InstantSearch

Customize content being indexed

Add custom meta data to my indexed post objects.

Even though Advanced Custom Fields is specific to Advanced Custom Fields, the code is largely the same even if you're not using ACF. You would need to change the examples from using get_field() to get_post_meta().

Restricting post types from being indexed

Autocomplete

Make use of algolia_excluded_post_types filter to exclude specific post types. See example filter callback at Filter Hooks

Instantsearch

You will need to intercept the found searchable post types and remove them from an array, instead of pushing the post type into an array. This is reverse from the available filter for Autocomplete.

function wds_algolia_exclude_searchable_post_types( $searchable_post_types ) {
	$remove = [ 'movie', 'tv_show' ];
	foreach( $searchable_post_types as $key => $type ) {
		if ( in_array( $key, $remove ) ) {
			unset( $searchable_post_types[ $key ] );
		}
	}
	return $searchable_post_types;
}
add_filter( 'algolia_searchable_post_types', 'wds_algolia_exclude_searchable_post_types' );
Clone this wiki locally