• Hi, it this compare correct?

    'meta_query' => array(
    			array(
    				'key' => '_visite_money', // solo se articoli non ancora valutati
    				'value' => '-1',
    				'compare' => '!=',
    				'type' => 'NUMERIC'
    			)
    		),

    should i use in ‘type’ value SIGNED?

Viewing 1 replies (of 1 total)
  • I had a similar issue where I was trying to find longitudes between two negative (western) longitudes.

    In the case of using IN BETWEEN for compare, setting type to DECIMAL(10,6) worked for me

    120                            $latitute_array = array(
        121                                'key' => 'user_latitude',
        122                                'value' => array($roughBoundBox[0], $roughBoundBox[2]),
        123                                'compare' => 'BETWEEN',
        124                                'type'   => 'DECIMAL(10,6)'
        125                            );
        126                            $metaQuery[] = $latitute_array;
        127
        128                            $longitude_array = array(
        129                                 'key' => 'user_longitude',
        130                                 'value' => array($roughBoundBox[1], $roughBoundBox[3]),
        131                                 'compare' => 'BETWEEN',
        132                                 'type'  => 'DECIMAL(10,6)'
        133                            );
        134                            $metaQuery[] = $longitude_array;
        135                        }

    Because you are using != I would assume the default CHAR would have worked.

    Just using DECIMAL rounds it to the nearest integer, which might work in your case. It depends if you are comparing fractional numbers or round integers. See https://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html .

    Numeric is also an accepted type (https://codex.www.ads-software.com/Class_Reference/WP_Query#Custom_Field_Parameters). But I didn’t use it and I don’t know at this time what is the difference between NUMERIC and DECIMAL.

    Julien
    https://www.credil.org

Viewing 1 replies (of 1 total)
  • The topic ‘meta compare negative value’ is closed to new replies.