1

I’m using a custom loop to display woocommerce products on a page, I need order it by range price and products ids like below :

$args = array(
        'post_type' => 'product',
        'orderby'   => 'ID', 
        'order'     => 'desc', 
        'meta_query' => array( 'relation ' => 'AND',
            array(
               'key' => '_price',
               'value' => array( $minPrice, $maxPrice ),
               'type' => 'numeric',
               'compare' => 'BETWEEN',
               'order' => 'asc')
         )
       );

Could someone help me? Thanks in advance

karim
  • 25
  • 5

1 Answers1

0

You can check this snippet.

$args = array(
        'post_status'   => 'publish',
        'post_type'     => 'product',
        'orderby'       => 'ID', 
        'order'         => 'asc', 
        'meta_query' => array(
            array(
                'key'      => '_price',
                'value' => array( $minPrice, $maxPrice ),
                'compare' => 'BETWEEN',
                'type' => 'NUMERIC'
            )
        )
    );

You can get more ideas from this kind of topics WooCommerce search products between price range using WP_Query

Biplob Ahmed
  • 106
  • 4