Created
October 12, 2020 13:30
-
-
Save felipeelia/40cc29f9a060d00e1ba1c8f57c2ff653 to your computer and use it in GitHub Desktop.
Exclude some terms form the ElasticPress Facets Widget Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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