[wp-hackers] Multiple orderby and order options in WP_Query
Eric Mann
eric at eam.me
Tue Apr 5 13:46:22 UTC 2011
Christian,
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:
> Hi!
>
> 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
> descending.
>
>
> 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
> );
>
> --
> Regards
> //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
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list