Can i merge 2 new WP_Query($variable) ‘s?

You won’t do much good just merging the arguments, you need to merge the resulting posts array and the post_count count. This works for me:

//setup your queries as you already do
$query1 = new WP_Query($args_for_query1);
$query2 = new WP_Query($args_for_query2);

//create new empty query and populate it with the other two
$wp_query = new WP_Query();
$wp_query->posts = array_merge( $query1->posts, $query2->posts );

//populate post_count count for the loop to work correctly
$wp_query->post_count = $query1->post_count + $query2->post_count;

Leave a Comment