Created
July 12, 2016 19:34
-
-
Save stevenspads/1392ac08ccf004af50c8c3a325fbff0d to your computer and use it in GitHub Desktop.
Merging WP_QUERY objects in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Your original 2 WP_Query results: | |
$query1 = new WP_Query($args_for_query1); | |
$query2 = new WP_Query($args_for_query2); | |
//Create a new WP_Query object to hold the joining of the 2 originals: | |
$joined_query = new WP_Query(); | |
$joined_query->posts = array_merge( $query1->posts, $query2->posts ); | |
//Update joined object's post count: | |
$joined_query->post_count = $query1->post_count + $query2->post_count; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment