Skip to content

Instantly share code, notes, and snippets.

@yuriitaran
Forked from DWboutin/Merge wp_query
Created March 7, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriitaran/65d3043a201429661232a2d9ee04a8af to your computer and use it in GitHub Desktop.
Save yuriitaran/65d3043a201429661232a2d9ee04a8af to your computer and use it in GitHub Desktop.
Merge 2 WP_Query()
<?php
$query1 = new WP_Query($arg1);
$query2 = new WP_Query($arg2);
$query = new WP_Query();
$query->posts = array_merge( $query1->posts, $query2->posts );
// we also need to set post count correctly so as to enable the looping
$query->post_count = count( $query->posts );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment