[wp-trac] [WordPress Trac] #36937: Order By Multiple Meta Keys doesn't work as expected

WordPress Trac noreply at wordpress.org
Tue May 24 23:22:12 UTC 2016


#36937: Order By Multiple Meta Keys doesn't work as expected
--------------------------+------------------------------
 Reporter:  alexdelgado   |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  4.5.2
 Severity:  normal        |  Resolution:  invalid
 Keywords:  close         |     Focuses:
--------------------------+------------------------------
Changes (by Funkatronic):

 * keywords:   => close
 * status:  new => closed
 * resolution:   => invalid


Comment:

 To order by multiple keys, you have to use different syntax:

 {{{#!php
 <?php
 $args =
     array(
         'post_type'              => 'post',
         'post_status'            => 'publish',
         'posts_per_page'         => 1,
         'no_found_rows'          => true,
         'update_post_meta_cache' => false,
         'orderby'                => array(
             'key1'               => 'DESC',
             'key2'               => 'ASC',
         ),
         'meta_query'             => array(
             'relation'           => 'AND',
             'key1' => array(
                 'key'            => 'key1',
                 'value'          => 'value1',
                 'compare'        => '='
             ),
             'key2' => array(
                 'key'            => 'key2',
                 'type'           => 'NUMERIC',
                 'compare'        => 'EXISTS',
             )
         )
     );
 }}}

 You have to explicitly name each meta clause in order to sort by that
 clause

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


More information about the wp-trac mailing list