WP_Query orderby and order options not used as expected
|Reported by:||beaulebens||Owned by:||ryan|
|Component:||Query||Keywords:||has-patch needs-testing 3.3-early|
In WP_Query, "orderby" allows you to specify multiple columns, separated by spaces, to order your results by.
You can only specify a single "order" value (ASC or DESC).
If you specify multiple values in "orderby", "order" is applied to the end of the list, or effectively to the last "orderby" column.
e.g. If a custom query specifies:
'orderby' => 'title date', 'order' => 'DESC'
it probably meant ORDER BY post_title DESC, post_date DESC (or maybe ASC, it's ambiguous), but I'll actually get:
ORDER BY post_title, post_date DESC
With MySQL's implied ASC on ORDER BY statements, this is the opposite of what I really wanted.
We should either drop support for multiple-column ordering, allow for a way to specify a sort order per orderby/column, or at the very least apply the "order" to the first column specified, which seems like it'd be more likely to be intended outcome.
See Also: #9978 for a sticky post bug that will need to implement this ordering logic as well.
Change History (6)
- Keywords needs-patch added
- Milestone changed from Unassigned to Future Release
- Priority changed from normal to low
- Severity changed from normal to minor