[wp-trac] [WordPress Trac] #17065: Independent ASC/DESC in multiple ORDER BY statement.
WordPress Trac
wp-trac at lists.automattic.com
Sun Apr 24 06:54:36 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: normal | Resolution:
Keywords: has-patch |
-------------------------+------------------------------
Changes (by dd32):
* keywords: needs-patch => has-patch
Comment:
> attachment 17065.diff added
* Implements multiple orderby's
* Orders by any Queried Meta Key Value
* Retains full back compat
* Implemented 3. from above, See the final binary example below, for
interests sake, thats lines 2371 & 2372 in the patch - To implement that
in a plugin would require to filter each orderby clause individually, or
to duplicate most of the block, or to perform black magic (regular
expressions)
* If no valid ordering is specified, it falls back to post_date as before
{{{
Usage:
(current usage, which still works)
orderby: 'date'
orderby: 'date' order: ASC
orderby: 'date title' order: DESC (Orders by date DESC, and title DESC)
orderby: 'MyMetaKey'
(New functionality)
order: ASC // If the order field is not specified by a item, this is used.
orderby: array( 'date' )
orderby: array( 'date', 'title' )
orderby: array(
array(
'field' => 'date',
'order' => 'DESC'
)
);
orderby: array(
array(
'field' => 'date',
'order' => 'DESC'
),
array(
'field' => 'title',
)
);
orderby: array(
array(
'meta_key' => 'MyMetaKey', // meta_key || meta_query MUST
query for this key, else it's ignored
'order' => 'DESC'
),
array(
'field' => 'title',
'order' => 'ASC'
)
);
orderby: array(
array(
'meta_key' => 'MyMetaKey', // defaults to ordering by
meta_value
),
array(
'meta_key' => 'MyMetaKey', // meta_key || meta_query MUST
query for this key, else it's ignored
'field' => 'meta_value_num', // Lets numerically order it
'order' => 'DESC'
)
);
Binary Ordering:
orderby: array(
array(
'field' => 'ID',
'value' => 10, // Binary ordering, This moves ID 10 to the
front, or back of the set. Can be used with any field.
'order' => 'DESC'
)
);
orderby: array(
array(
'field' => 'ID',
'value' => 10,
'order' => 'DESC'
),
'rand' // post ID 10 is at the start of the list, Remaining
items are randomly sorted.
);
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17065#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list