Skip to content

Instantly share code, notes, and snippets.

@temsool
Created April 17, 2023 10:01
Show Gist options
  • Save temsool/5db1844870a8ab4c0623943cc82fea7a to your computer and use it in GitHub Desktop.
Save temsool/5db1844870a8ab4c0623943cc82fea7a to your computer and use it in GitHub Desktop.
Tax Query elementor tax_query
<?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 );
});
?>
@dexit
Copy link

dexit commented Jan 15, 2024

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')) {

    // Check if it's an archive page or an archive category page, but not the SHOP page
    if ((is_archive() || is_category()) && is_shop()) {

$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;
});

@temsool
Copy link
Author

temsool commented Jan 15, 2024

@dexit Ah, Thank you 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment