Allow DECIMAL Precision in WP_Query Meta Queries
|Reported by:||dominicp||Owned by:|
As of now, if we specify a precision for the DECIMAL type in WP_Query meta queries [e.g. DECIMAL(4,2)], the type is changed to CHAR. This transformation seems to happen here:
As a work around, we can add a filter to the get_meta_sql hook and manually change DECIMAL to DECIMAL(X,X) with a str_replace, but that seems pretty clumsy and it forces us to pick one level of precision for all meta queries.
As a solution, right above the line I have linked above, we could add a conditional that checks if the type starts with DECIMAL, and then uses a regex to check if the format for the precision is correct. Of course, another option would be to add a precision key to the meta query array like so:
array( 'key' => 'meta_key', 'value' => $value, 'type' => 'DECIMAL', 'compare' => '>', 'precision' => array( 4, 2 ) ),
I apologize if this question has already been asked, or if I'm missing something obvious. But, to me it seems like the current system is a bit limiting. Thanks.