Leave a Reply

2 comments

  1. For decimal numbers, you should use ‘DECIMAL’ in place of ‘NUMERIC’

    $array[] = array(
        'key' => 'd_weight',
        'value' => array(0.1,0.5),
        'compare' => 'BETWEEN',
        'type' => 'DECIMAL'
    );
    
  2. Mridul’s answer is partially correct, but there’s more to it in the OP’s case, specifically when dealing with the BETWEEN comparison. After changing from type=NUMERIC to type=DECIMAL, you also need special handling to filter the way WP typecasts to the DECIMAL datatype (otherwise it will use the default precision.) Very rough example below:

    function wp_get_meta_sql_cast_decimal_precision($meta_query) {
        $meta_query['where'] = str_replace('DECIMAL', 'DECIMAL(10,3)', $meta_query['where']);
        return $meta_query;
    }
    add_filter('get_meta_sql', 'wp_get_meta_sql_cast_decimal_precision');