I'm creating two different WP_Query objects, one for each of two different post types I'm using. In creating my output, I'd like to loop through one of the objects, and at the same time loop through the other object as well, so I can output pieces of them together. Here's an example of what I'd like to accomplish:
$rotator_args = array(
'post_type' => 'rotator',
);
$rotator = new WP_Query($rotator_args);
$numrotators = $rotator->post_count;
$testimonial_args = array(
'post_type' => 'testimonial',
'posts_per_page' => $numrotators,
);
$testimonial = new WP_Query($testimonial_args);
while ( $rotator->have_posts() ) :
$rotator->the_post(); //setup the rotator posts
$testimonial->the_post(); //this breaks things, understandably
$rotator_image = get_the_post_thumbnail($rotator->ID, 'large');
$testimonial_image = get_the_post_thumbnail($testimonial->ID, 'large');
$return .= '<div>' . $rotator_image . '</div>';
$return .= '<div>' . $testimonial_image . '</div>';
endwhile;
return $return;
However, that doesn't work. Taking out $testimonial->the_post();
(and the associated $testimonial
related code) fixes things.