I would like to display some “artworks” with specifics meta key values. Each artworks has a custom field : “votes_average” and another one “votes_count”. This is my custom query :
$args = array(
'post_type' => 'artworks',
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'votes_average',
'value' => '6',
'compare' => '>=',
'type' => 'DECIMAL',
),
array(
'key' => 'votes_count',
'value' => '1',
'compare' => '>',
'type' => 'NUMERIC',
),
),
'tax_query' => array(
array(
'taxonomy' => 'type',
'field' => 'slug',
'terms' => $term
)
)
);
I don’t understand why this query display an artwork with an average of 5,8. Did I make a mistake ?
The problem is that MySQL rounded 5.8 to 6 and used in the query. Appropriate query portion looks like
So you can replace DECIMAL with NUMERIC to solve this issue.