[wp-trac] [WordPress Trac] #17065: Independent ASC/DESC in multiple ORDER BY statement.

WordPress Trac wp-trac at lists.automattic.com
Sun Apr 24 00:21:04 UTC 2011


#17065: Independent ASC/DESC in multiple ORDER BY statement.
-------------------------+------------------------------
 Reporter:  ericmann     |       Owner:  ericmann
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:  3.1
 Severity:  trivial      |  Resolution:
 Keywords:  needs-patch  |
-------------------------+------------------------------

Comment (by dd32):

 An alternate syntax could be:

 {{{
 1. $args = array(
   'post_type => 'post',
   'orderby' => array(
     array(
       'meta_key' => 'bar',
       'order' => 'DESC',
     ),
     'date DESC'
   )
 )
 }}}
 ie. Only use a multi dimension array when it's actually needed, Since
 we've currently got orderby as well as order, we could simplify it to (ie.
 abide by $order if set)
 {{{
 1b. $args = array(
   'post_type => 'post',
   'order' => 'DESC',
   'orderby' => array(
     array( 'meta_key' => 'bar' ),
     'date'
   )
 )
 }}}

 The other obvious one, which I don't really like due to the "new" syntax
 of it:
 {{{
 2. $args = array(
   'post_type => 'post',
   'orderby' => array(
     'meta_key:bar DESC',
     'date DESC'
   )
 )
 }}}

 And to drop a bombshell here, One thing that I've had to implement "often"
 when someone wants a custom ordering, is to float one value to the front
 of the list, such as:
 {{{
 3. $args = array(
   'post_type => 'post',
   'orderby' => array(
     array(
       'meta_key' => 'bar',
       'meta_value' => 'first',
       'order' => 'DESC', // Ie. "ORDER BY (meta_key_bar === 'first') DESC"
     ),
     'date DESC'
   )
 )
 }}}
 This one is a step over what we currently have however, and can easily be
 achieved through existing filters, so whatever is added here, we'll need
 to ensure that extending upon it is possible.

 I'll whip up a patch for number 1 above and a example of implementing 3 in
 a plugin..

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17065#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list