WP - exclude tag from custom taxonomy in search results

Hi there,

I’m working with a WP site which has a custom taxonomy, ‘topics’, with one of the tags in that taxonomy called ‘excluded’.

I’m looking to stop any searchable_posts with the ‘excluded’ tag from being indexed, but am unsure how to go about it. I was hoping I’d be able to do something like:

function exclude_taxonomy( $should_index, WP_Post $post ) {
   $excluded_post_types = array( 'excluded' );

    if ( false === $should_index ) {
        return false;

    return ! in_array( $post->post_tag, $excluded_post_types, true );

but unfortunately that hasn’t worked. Could anyone point me in the right direction?

Thanks a lot


Did you try manually deleting your indices from the Algolia dashboard an re-index after having implemented your code?

The code above will only ensure no newly post would be indexed for the excluded taxonomies, but it will not delete already indexed posts.