Created
April 17, 2023 10:01
-
-
Save temsool/5db1844870a8ab4c0623943cc82fea7a to your computer and use it in GitHub Desktop.
Tax Query elementor tax_query
This file contains 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 | |
add_action( 'elementor/query/solutionQuery', function( $query ) { | |
$tremID=get_queried_object_id(); | |
$query->set( 'posts_per_page', -1 ); | |
$query->set( 'post_type', 'solution' ); | |
$tax_query = array( | |
array( | |
'taxonomy' => 'solution_range', | |
'field' => 'term_id', | |
'terms' => $tremID, | |
), | |
); | |
$query->set( 'tax_query', $tax_query ); | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just in case, for Product Attribute :
add_action( 'elementor/query/productQuery', function( $query ) {
// Check if it's the main query and if WooCommerce is active
if ($query->is_main_query() && class_exists('WooCommerce')) {
$tremID=get_queried_object_id();
$query->set( 'posts_per_page', -1 );
$query->set( 'post_type', 'product' );
$tax_query = array(
array(
'taxonomy' => 'pa_delivery', // atribute
'field' => 'term_id',
'terms' => $tremID,
),
);
$query->set( 'tax_query', $tax_query );
}
}
return $query;
});