Hi all,
I ran into a situation today where I had to merge two queries into one & I haven't had to do that till now. I found some documentation on merging a second query into the primary one (everything used query_posts, not WP_Query), but nothing on taking two new queries & smashing them together. I think I got it right (I got nice output) but I wanted to put this out there for others to see. I'd love feedback on it. I don't know what kind of performance hit this might cause or if there's a better way to do it.
What I have is a page template that needs to have a listing of two groups of child pages.
I wrote a query for both:
$query1 = new WP_Query(array(
'post_type' => 'page',
'post_parent' => 341,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
));
$query2 = new WP_Query(array(
'post_type' => 'page',
'post_parent' => 109,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
));
Then I used array_merge to combine the posts array from each set of results:
$querysmash = array_merge($query1->posts, $query2->posts);
After that, it's a foreach statement to loop through the array:
foreach ($bigm as $post) : setup_postdata($post);
// Do something
endforeach; wp_reset_postdata();
Thoughts?