Howdy @jdingman
The checkboxes on the WP-Admin -> Algolia Search -> Autocomplete screen are to configure Autocomplete, not to configure the search page or the searchable_posts
index itself.
The “All Posts” (searchable_posts
) index is used by the Instantsearch.js (“Use Algolia with Instantsearch.js”) and PHP backed search (“Use Algolia in the backend”) integrations configured at WP-Admin -> Algolia Search -> Search Page. If you are trying to affect the search page specifically, then searchable_posts
is indeed the index you want to work with.
By default, the searchable_posts
index will include content from all post types that were registered with exclude_from_search
set to false
. That is to say, post types that are normally searchable anyway (refer to Algolia_Plugin::load_indices()
).
After retrieving the array of registered searchable post types, they are passed through the algolia_searchable_post_types
filter to allow for developer customization.
To limit the post types available to the searchable_posts
index, you would want to hook into algolia_searchable_post_types
, and return an array that _only contains_ the post types you _do_ want to index.
For example, if I wanted to limit the post types that are allowed in the searchable_posts
index to just two specific post types “book” and “movie”, I could do something like this:
/**
* Override the post types used for the "All Posts" (<code>searchable_posts</code>) index.
*
* @param array $searchable_post_types Array of searchable post types.
*
* @return array
*/
function myprefix_override_searchable_post_types( $searchable_post_types ) {
return [
'book',
'movie',
];
}
add_filter( 'algolia_searchable_post_types', 'myprefix_override_searchable_post_types' );
After applying that filter in code, you would need to re-index by clicking the “Re-index search page records” button at top of WP-Admin -> Algolia Search -> Search Page, or by using the wp algolia reindex
WP-CLI command.
For clarification, as I think there may be some confusion around the checkboxes, the checkboxes on WP-Admin -> Algolia Search -> Autocomplete screen are for configuring one or more indexes to be used by the Autocomplete.js integration, which is generally tied to a search field in a widget, header, footer, not tied to the “search page” specifically. The “All Posts” (searchable_posts
) index is available as a checkbox there, so that Autocomplete can use the same index that the search page uses. Alternatively, specific post types can be selected so that Autocomplete creates a new index for each individual post type. Searches in the Autocomplete drop down will then display headers for each index that was enabled on the WP-Admin -> Algolia Search -> Autocomplete screen.
Does that information help?