I am attempting to control a loop I have within a loop. What I would like to do is display all post and have a custom post type inserted every 3 post. So it would be like this "post post post CPT post post post cpt..." I accomplished this by doing this
global $loop_counter;
$loop_counter = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
?>
// DO STUFF
<?php $loop_counter++; ?>
if ( $loop_counter%3 == 0 ) {
$args = array(
'post_type' => 'testimony',
);
$testimony = new WP_Query($args);
if ( $testimony->have_posts() ) {
while ( $testimony ->have_posts() ) {
$testimony->the_post();
?>
//LOOP WITHIN LOOP
} }
} END loop count if
?>
I slimmed down the code a bit but this should be enough. Now this is working like I want with one issue. The inner loop keeps repeating as long as the main loop has posts. I want the stop looping through the inner loop as soon as we are out of posts to display. Any help would be appreciated.