Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

jeremyschultz on "Merging post wp_queries with array_merge not working"

$
0
0

I'm attempting to get a set of posts with a wp_query, and if it returns less than two I make a second wp_query and merge the results. In my test case, I get one result on query #1 and two on query #2 but in all cases the combined query #3 is empty.

<?php $query = new wp_query( array ( 'posts_per_page' => '2', 'orderby' => 'date', 'category_name' => 'as,ac,ai', 'cat' => '96,-31,-98', 'post__not_in' => array(718) ) );
if (($query -> post_count) < 2) {
	$query2 = new wp_query( array ( 'posts_per_page' => '2', 'orderby' => 'date', 'category_name' => 'as,ac,ai', 'cat' => '-96,-31,-98', 'post__not_in' => array(718) ) );
	//echo $query -> post_count; returns 1
	//echo $query2 -> post_count; returns 2
	$query3 = array_merge($query, $query2);
	//echo "query3 post count is " . $query3 -> post_count; returns blank
	//print_r($query3); nothing
}

I've tried everything I can think of and nothing returns anything. What am I missing?


Viewing all articles
Browse latest Browse all 8245

Trending Articles