[wp-trac] [WordPress Trac] #19802: Allow DECIMAL Precision in WP_Query Meta Queries

WordPress Trac wp-trac at lists.automattic.com
Wed Jan 11 06:50:06 UTC 2012


#19802: Allow DECIMAL Precision in WP_Query Meta Queries
-------------------------+--------------------------------------
 Reporter:  dominicp     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  3.3.1
 Severity:  normal       |   Keywords:  2nd-opinion dev-feedback
-------------------------+--------------------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19802>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list