Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save felipeelia/40cc29f9a060d00e1ba1c8f57c2ff653 to your computer and use it in GitHub Desktop.
Save felipeelia/40cc29f9a060d00e1ba1c8f57c2ff653 to your computer and use it in GitHub Desktop.
Exclude some terms form the ElasticPress Facets Widget Filter
<?php
// Exclude some terms form the ElasticPress Facets Widget Filter
add_action(
'pre_get_terms',
function ( $wp_term_query ) {
global $wp_query;
if ( ! $wp_query->get( 'ep_facet', false ) ) {
return false;
}
$feature = \ElasticPress\Features::factory()->get_registered_feature( 'facets' );
if ( ! $feature->is_active() || ! $feature->is_facetable( $wp_query ) ) {
return false;
}
if ( in_array( 'category', $wp_term_query->query_vars['taxonomy'], true ) ) {
$wp_term_query->query_vars['exclude_tree'] = [ 1 ]; // Term IDs to exclude.
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment