[wp-hackers] Multiple orderby and order options in WP_Query
eric at eam.me
Tue Apr 5 13:46:22 UTC 2011
My recommendation would be to use one orderby statement in the query, then
filter the array returned to order by your second parameter.
MySQL does support ordering by multiple columns, but not in the sense of
ordering one ASC and the other DESC. So separate your two paradigms, let
MySQL take care of one for you, then manually do the other via PHP.
On Tue, Apr 5, 2011 at 5:43 AM, Christian Gundersson <christian at buro2.se>wrote:
> I have a situation where I want to order a list of post both by author and
> date using WP_Query which isn't a problem since 'orderby' lets me do that.
> But I want the author part sorted ascending and date part sorted
> Any tips on how I can achieve this?
> The arguments I pass to WP_Query are:
> $author_args = array (
> 'post_type' => 'post',
> 'posts_per_page' => '-1',
> 'orderby' => 'author date',
> 'order' => 'ASC',
> 'nopaging' => true,
> 'category_name' => $category_name
> //Christian, Büro 2
> Büro 2
> Skolgatan 5
> 262 31 Ängelholm
> 0763-91 55 85
> christian at buro2.se
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers