Opened 16 months ago
Last modified 16 months ago
#19802 new enhancement
Allow DECIMAL Precision in WP_Query Meta Queries
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 3.3.1 |
| Severity: | normal | Keywords: | 2nd-opinion dev-feedback |
| 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.
