1

I have a collection of posts and first I want to order them by 'name' in ASC order and then order by 'date' in ASC order. How does one go about doing this?

1 Answer 1

5

Multiple orderby with different sort order values are possible as of WordPress 4.0, take a look at the codex page for WP_Query - Order - Orderby Parameters. There is an related Make WordPress Core article too.

The following example would comply to what you want:

$query = new WP_Query(
    array(
        'orderby' => array(
            'name' => 'ASC',
            'date' => 'ASC'
        )
    )
);
3
  • @user1848902 Please consider accepting this answer as this has clearly answered your question. Just look for the checkmark next to this answer and click it once. For more info, check help center and visit the tour page Sep 10, 2014 at 17:05
  • 1
    Glad that this has finally made it to core. Sep 10, 2014 at 17:06
  • 1
    @PieterGoosen Overdue like forever! Sep 10, 2014 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.