Howdy!
TSF developer here. This ought to work (code is untested, use at own risk):
add_filter( 'algolia_should_index_searchable_post', 'my_algolia_tsf_filter_post', 10, 2 );
/**
* Don't index pages where the robot index option
* in The SEO Framework plugin is set to noindex.
*
* @param bool $should_index Whether post should be indexed.
* @param WP_Post $post The post to filter.
* @return bool
*/
function my_algolia_tsf_filter_post( $should_index, $post ) {
if ( false === $should_index ) return false;
static $has_tsf;
if ( ! isset( $has_tsf ) )
$has_tsf = function_exists( 'tsf' );
if ( ! $has_tsf ) return true;
return 'noindex' !== ( tsf()->generate_robots_meta( [ 'id' => $post->ID ], [ 'noindex' ] )['noindex'] ?? null );
}
What @cybr said looks legit, and definitely returns a true/false value based on what the code determines.
Looks like it’ll return false still if the $should_index is already determined to be false, and then also return true if somehow The SEO Framework isn’t found, but it already made it that far.
Lastly, it checks for the meta robots tag and returns false if it’s set to noindex, meaning it shouldn’t be indexed.
Thanks for hopping in as well Sybre
Thread Starter
WP_User
(@amarudare)
Thank you for the prompt reply Sybre and Michael. I added the code, Re-indexed the pages, cleared the cache and tried to search. The page that I am trying to exclude still shows in autocomplete suggestions.
You may need to use the algolia_should_index_post filter for autocomplete. The filter suggested above I believe is for the instantsearch.
There should be “re-index” buttons on the autocomplete settings page alongside each content type, that would help with bulk re-indexing those.
Thread Starter
WP_User
(@amarudare)
Hey Micahel,
Apologies if I am wrong.
While a user types a term, the suggested pages and posts are available below the search box. My understanding is that this is the instant search function. This is what I am trying to exclude.
Can you please clarify?
Any suggestions provided below the search field while typing in the input, is the autocomplete suggestions. The page you see when visiting mysite.com/?s=myquery would be the instantsearch results.
Worst case, in case we want to test that we’re at least getting the code in the right place, immediately return false and see if all your content is de-indexed. If yes, then we at least know the code is running, and it’s the conditions inside it that aren’t matching up yet.
Thread Starter
WP_User
(@amarudare)
It worked. Maybe it was a caching issue. Thank you @tw2113 and @cybr!