Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save slaffko1/aae9ef4337e9d0450a2c2fbe8d091bec to your computer and use it in GitHub Desktop.
Save slaffko1/aae9ef4337e9d0450a2c2fbe8d091bec to your computer and use it in GitHub Desktop.
WooCommerce search products between price range using WP_Query
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('clothing'),
'operator' => 'IN'
),
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'color',
'value' => 'red',
'compare' => '=',
),
array(
'key' => '_price',
'value' => array(30,40),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
)
),
);
$the_query = new WP_Query( $args );
echo $count = $the_query->post_count;
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
endif;
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment