wp query – meta_query weird behaviour, static int will work, but not user data

Question

I am currently trying to build a Ajax filter for a CPT, all the products have a min and max value of a specific range in which the products works best. Therefore i created ACF groups with a min and max value as a number field.

When i am trying to add the meta_query with the static values listed below, i am able to find the corresponding product, however when i replace the 1,200 with the $min and $max (they are for sure integers) the query returns 0 products and doesn’t find the product.

I have no idea how this is possible, as i am feeding the exact same type to the query. Any idea what can cause this issue?

foreach ($filter_data as $data ) {

    $stripped_id = str_replace('slider-', '', $data['id']);
    $stripped_id = str_replace('-range', '', $stripped_id);   

    $min = intval($data['min']);
    $max = intval($data['max']);

    array_push( $metaquery, array(
        'key'       => 'ultimate-torque_min',
        'value'     => array( 1, 200 ),
        'compare'   => 'BETWEEN',
        'type'      => 'NUMERIC'
    ));

    array_push( $metaquery, array(
        'key'       => 'ultimate-torque_max',
        'value'     => array( 1, 200 ),
        'compare'   => 'BETWEEN',
        'type'      => 'NUMERIC'
    ));

}

0
AliasElias 4 months 2022-07-22T16:54:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse