[wp-trac] [WordPress Trac] #41546: WP Query order by meta_clause NUMERIC not working correctly for decimal values

WordPress Trac noreply at wordpress.org
Thu Aug 3 13:06:38 UTC 2017


#41546: WP Query order by meta_clause NUMERIC not working correctly for decimal
values
------------------------------+-----------------------------
 Reporter:  LordSpackolatius  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Query             |    Version:  4.8.1
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 Short description: When using the WP 4.2 improvements for meta queries (as
 described here: https://make.wordpress.org/core/2015/03/30/query-
 improvements-in-wp-4-2-orderby-and-meta_query/) and trying to order the
 query by a decimal custom field, wordpress orders as if these fields are
 all integer and incorrectly handles all decimal values such as 1.5, 1.6
 and 1.7 (all of these are seen as 1).

 In detail:

 {{{
 WP_QUERY_ARGS Array
 (
     [ignore_sticky_posts] => 1
     [post_status] => publish
     [offset] => 0
     [post_type] => Array
         (
             [0] => post
         )

     [orderby] => Array
         (
             [cf_clause_1] => DESC
             [ID] => ASC
         )

     [meta_query] => Array
         (
             [cf_clause_1] => Array
                 (
                     [key] => my_decimal_custom_field
                     [type] => DECIMAL
                     [compare] => EXISTS
                 )

         )

     [posts_per_page] => 10
     [nopaging] =>
 )
 }}}

 5 Test posts:
 Post 1 - my_decimal_custom_field = 1
 Post 2 - my_decimal_custom_field = 2
 Post 3 - my_decimal_custom_field = 2.2
 Post 4 - my_decimal_custom_field = 2.6
 Post 5 - my_decimal_custom_field = 3

 Using the query above results in the order:
 1,3,4,2,5

 When it should be 1,2,3,4,5.

 Trying out different order types as described in the WP Codex does not
 help.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41546>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list