[wp-trac] [WordPress Trac] #38442: Error when WP_Query parses orderby array in function parse_order

WordPress Trac noreply at wordpress.org
Fri Mar 29 19:53:10 UTC 2019


#38442: Error when WP_Query parses orderby array in function parse_order
--------------------------------------+-----------------------------
 Reporter:  oloynet                   |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Future Release
Component:  Query                     |     Version:  4.2
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------
Changes (by desrosj):

 * keywords:  has-patch 2nd-opinion needs-unit-tests => has-patch has-unit-
     tests
 * version:  4.6.1 => 4.2
 * milestone:  Awaiting Review => Future Release


Comment:

 I dug into this to understand it a bit better. In the current state,
 ordering by multiple meta keys only works when using explicit indexes. For
 example, if the query in your example is changed to this, @oloynet, I am
 seeing the correct SQL generated:

 {{{
 'meta_query' => array(
         'relation' => 'AND',
         'date_meta' => array(
                 'key'  => 'start_date_order',
                 'type' => 'UNSIGNED',
         ),
         'sticky_meta' => array(
                 'key'  => 'is_sticky',
                 'type' => 'UNSIGNED',
         ),
 ),
 'orderby' => array(
         'date_meta'.  => 'DESC',
         'sticky_meta' => 'ASC',
 ),
 }}}

 [attachment:"38442.diff"] is a refresh of the original patch accompanied
 by unit tests and a few changes:

 - We don't need to declare `$primary_meta_query = false;`. That is
 redundant since the same declaration is just outside the `if` statement.
 - Use strict comparison wghen comparing `key` with `$orderby`.
 - Add a check that `$meta_clause['key']` is actually set to avoid PHP
 notices.

 If you only add the unit test, the tests will fail. Adding the other part
 of the patch will result in the tests passing.

 @boonebgorges Are you able to review?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38442#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list