Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere

You could do something like :

$related_posts_query = new WP_Query( $related_posts_args );
if( $related_posts_query->found_posts < 10 ){
   $args = array(/* new wp_query args*/);
   $newquery = new WP_Query( $args );
}

# merge the two results
$related_posts_query->posts = array_merge( $related_posts_query->posts, $newquery->posts );
$related_posts_query->post_count = count( $related_posts_query->posts );

# do your loop here

Leave a Comment