Closed marco910 closed 1 year ago
If you're using this primarily for Autocomplete, I know that those often get their own index each, but there's also the "All posts" option on the autocomplete page that uses the wp_searchable_posts
index which is all in one, based on if the given post type is registered as searchable.
Probably not 100% ideal, but if memory serves me correct, this is how Algolia was doing things before we forked their abandoned WP plugin for continued development. Saying this just to illustrate that it was a decision they originally made, that we haven't changed to avoid backwards compatibility breaking.
@tw2113 Many thanks! The option "All posts" was there all the time, but I didn't see it... Now all posts are in one index.
Is there a way to prevent some post types from being pushed in to Algolia when using the "all posts" option? Maybe a PHP hook or something similar?
Check the code samples at https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Filter-Hooks and the first one should be how to exclude specific post types from being considered for the index, as well as what should already be getting excluded by default with the latest version of the plugin.
Closing as not a feature/bug report, but we can keep commenting if/as needed.
@tw2113 Great! I will have a look at this
@tw2113 I've added this code to my functions.php
as described in your docs, but it's not working. All other filters for this plugin are working. Still, all post types are getting included. Any ideas?
function fw_algolia_exclude_post_types(array $exclude) {
$exclude[] = 'post_type_a';
$exclude[] = 'post_type_a';
return $exclude;
}
add_filter( 'algolia_excluded_post_types', 'fw_algolia_exclude_post_types');
@marco910 You will have to do a bulk re-index to get the intended excluded posts types out of your index. It's not something that runs automatically, otherwise we'd be having to push to the API constantly.
@marco910 You will have to do a bulk re-index to get the intended excluded posts types out of your index. It's not something that runs automatically, otherwise we'd be having to push to the API constantly.
@tw2113 I've clicked on "Re-Index" for "All posts" in the plugin settings, it reindexed all posts, but the above script didn't work. Also, when I delete them manually out of the Algolia index, it adds them back to the index.
Are you making sure to be doing the re-index from the correct place? For example if you're on the searchable posts settings page, and these are meant for autocomplete, then that's not going to match up, and you'd want to use the line item "re-index" buttons from the autocomplete settings pages
That's my current setting under "Autocomplete" (all other post types are disabled). If I disable the checkbox in front of the row, the sync when publishing or editing posts won't work anymore.
When I click on "Re-Index" after adding the code to my functions.php
, the post types, that should be excluded, are still included.
Checking on some things.
Just a quick update, it looks like the bulk re-indexing, after excluding a post type, is actually not removing the previous content for myself as well, which feels like an odd spot to be putting people in. This is because it ends up requiring manual removal as is, and that doesn't quite feel appropriate.
So I'm discussing internally to see what others think regarding this and how we could potentially handle.
Hey @marco910 I managed to remember the following filter and it looks like it's doing what we need/should logically expect with bulk indexing as well, for searchable posts. However it's not set up quite like algolia_excluded_post_types
where you just specify the post type to exclude. Below is an example that would remove "page" and "attachment" from the indexing, after save of the code, and then a bulk re-index from the search settings page.
function fw_algolia_exclude_searchable_post_types( $searchable_posts ) {
$remove = [ 'page', 'attachment' ];
foreach( $searchable_posts as $key => $type ) {
if ( in_array( $key, $remove ) ) {
unset( $searchable_posts[ $key ] );
}
}
return $searchable_posts;
}
add_filter( 'algolia_searchable_post_types', 'fw_algolia_exclude_searchable_post_types' );
@tw2113 Many thanks for this and your help! Now it works to exclude specific post types.
Awesome to hear
Hi there,
I'ms using this plugin on my headless WordPress site to push posts from multiple custom post types to Algolia. Currently, for every custom post type that is pushed, one index is created. But is it possible to push everything into one single index?