extended-cpts icon indicating copy to clipboard operation
extended-cpts copied to clipboard

Problem with use meta in WP_QUERY

Open ImaggoDev opened this issue 4 years ago • 2 comments

Hi, I loved extended-cpts! But i dont understand how to use meta keys in wp_query. This is my code:

'site_filters' => [
     'price_from' => [
         'meta_key' => 'flat_price',
           'meta_query' => [
              'compare' => '>=',
               'type'    => 'NUMERIC',
            ],
         ],
]

If i go to url domain/flats/?price_from=200000 everything works. Query found only posts where field flat_price >= $_GET['price_from'] , and this is awesome, but i have a problem with use this in WP Query via AJAX. Code:

    $args = array(
        'post_type' => 'flat',
        'paged' => $paged,
        'price_from' => 200000,
    );

    $query = new \WP_Query($args);
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            ...
        }
    }

and it doesnt work. Query find all flats also when flat_price is for example 1000. I tried change int to string in $args ['price_from' => '200000'] but also doesnt work. How to use meta keys in wp query and how to use when i have manyyy meta query data.

ImaggoDev avatar Dec 14 '21 21:12 ImaggoDev

This should work. Let me look into it.

johnbillion avatar Dec 14 '21 21:12 johnbillion

Hi, @johnbillion did you have time to reproduce this error?

grzesiek1owline avatar Jan 10 '22 19:01 grzesiek1owline