Opened 13 years ago
Closed 11 years ago
#19802 closed enhancement (duplicate)
Allow DECIMAL Precision in WP_Query Meta Queries
Reported by: | dominicp | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
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:
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/meta.php#L716
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.
Moving this to 3.7, I haven't patched it yet, but I can already tell how bad we are blowing it here