• Resolved proguid

    (@procarmanuals)


    You need to exclude the category for search engine optimization.
    I already have a wordpress based functionality where category id is excluded, but Algolia Autocomplete ignores this filter.
    Is there a possibility to exclude posts of a certain category?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @procarmanuals

    You can use something like this below. Just fill in the appropriate intended value in the has_category() line.

    function wds_algolia_filter_post( $should_index, WP_Post $post ) {
    
    	// Fill in your category name/slug/ID
        if ( has_category( 'some-category-name', $post->ID ) ) {
        	// Post has the category, so we do NOT want to index
            return false;
        }
    
        // Return whatever value this was, probably boolean true.
        return $should_index;
    }
    add_filter( 'algolia_should_index_searchable_post', 'wds_algolia_filter_post', 10, 2 );
    add_filter( 'algolia_should_index_post', 'wds_algolia_filter_post', 10, 2 );

    I have included a filter for this for Instantsearch/searchable posts indexes as well, just in case. If you don’t need that, you can remove this line:

    add_filter( 'algolia_should_index_searchable_post', 'wds_algolia_filter_post', 10, 2 );

    Hope that helps

    Thread Starter proguid

    (@procarmanuals)

    It worked. Thank you!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Won’t hurt to do a bulk reindex, in case you haven’t to clear out the index for all posts that have that category.

    Thread Starter proguid

    (@procarmanuals)

    Yeah, that’s exactly what I did.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude a category from the search’ is closed to new replies.