I have an WP_Query array made up from two WP_Query() objects merged together as follows:

$query1 = new WP_Query($args1);
$query2 = new WP_Query($args2);     

$wp_query = new WP_Query();
$wp_query->posts = array_merge( $query1->posts, $query2->posts );

Each of the original queries are ordered by name - 'orderby' => 'post_name' - but array merge doesn't obviously respect that.

Does anyone know a way to sort $wp_query arrays after they have been populated? Or do I have to fathom and write a custom php sorting function of my own?


  • 2
    Not sure if this helps, but php's array_multisort function allows you to sort by key value. php.net/manual/en/function.array-multisort.php – gdaniel Dec 10 '14 at 15:27
  • Agreed. More of a pure PHP question I think. – Rarst Dec 10 '14 at 17:29
  • Thanks for the comments - had arrived at the same conclusion. array_multisort it is then - fun fun – Screenbeetle Dec 10 '14 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.