Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created February 7, 2014 14:17
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DWboutin/8863377 to your computer and use it in GitHub Desktop.
Save DWboutin/8863377 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 );
?>
@phuwin
Copy link

phuwin commented May 30, 2016

Thanks for your snippets. The 11th line of code is very important!!!!

@ekasur
Copy link

ekasur commented Oct 24, 2016

guys, How to display the data ? like title, custom post, etc ?

I try, $query->title(); is not working ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment