Algolia - WordPress - Exclude multiple taxonomies from indexing -
1) trying exclude taxonomy being indexed algolia. can not make work. code:
function exclude_taxonomy( $should_index_category, wp_post $post ) { // add post types don't want make searchable. $excluded_event_categories = array( 'post_type' => 'events', 'tax_query' => array( array( 'taxonomy' => 'events_category', 'field' => 'slug', 'terms' => 'xclude', ) ), ); if ( false === $should_index_category ) { return false; } return ! in_array( $post->taxonomy, $excluded_event_categories, true ); } // hook algolia manipulate post should indexed. add_filter( 'algolia_should_index_searchable_post', 'exclude_taxonomy', 10, 2 );
2) how multiple taxonomies. have second 1 goes:
'tax_query' => array( array( 'taxonomy' => 'events_status', 'field' => 'slug', 'terms' => 'archive', ) ),
thank you.
i think issue around $excluded_event_categories
variable.
i believe code should should similar following snippet. if understood correctly, want exclude events_category
, event_category
being indexed.
function exclude_taxonomy( $should_index_category, wp_post $post ) { if ( false === $should_index_category ) { return false; } return ! in_array( $post->taxonomy, array('events_category', 'events_status'), true ); } // hook algolia manipulate post should indexed. add_filter( 'algolia_should_index_searchable_post', 'exclude_taxonomy', 10, 2 );
Comments
Post a Comment