Make WordPress Core

Opened 12 years ago

Closed 10 years ago

#19802 closed enhancement (duplicate)

Allow DECIMAL Precision in WP_Query Meta Queries

Reported by: dominicp's profile dominicp Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Query Keywords:
Focuses: Cc:


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:

  '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.

Change History (3)

#1 @SergeyBiryukov
12 years ago

  • Component changed from General to Query

#2 @wonderboymusic
10 years ago

  • Keywords needs-patch added; 2nd-opinion dev-feedback removed
  • Milestone changed from Awaiting Review to 3.7

Moving this to 3.7, I haven't patched it yet, but I can already tell how bad we are blowing it here

#3 @wonderboymusic
10 years ago

  • Keywords needs-patch removed
  • Milestone 3.7 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#23033 has a patch

Note: See TracTickets for help on using tickets.