Support » Plugin: WooCommerce » searching for price range in myPHPAdmin

  • andy3000


    When I use myPhpAdmin to search the postmeta table for say a product priced at 8000.00 using LIKE or %LIKE% I get the correct result.
    If I try to use BETWEEN and enter 7000.00 AND 9000.00 I get an error.
    How can I search for prodcts in a price range using myPhpAdmin

Viewing 1 replies (of 1 total)
  • Hi Andy,
    You can try this query:

    SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
    INNER JOIN $wpdb->postmeta ON ID = post_id
    WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish' AND meta_key = '_price' AND meta_value BETWEEN 7000 AND 9000

    Otherwise you can try to build a function like:

    $query = array(
        'post_status' => 'publish',
        'post_type' => 'product',
        'posts_per_page' => 10,
        'meta_query' => array(
                'key' => '_price',
                'value' => array(7000, 9000), //or just set 8000 here
                'compare' => 'BETWEEN',
                'type' => 'NUMERIC'
    $wpquery = WP_Query($query); 

    And try to display it on your page.

    I hope that will help.


Viewing 1 replies (of 1 total)
  • The topic ‘searching for price range in myPHPAdmin’ is closed to new replies.