I think you want something more like this:
$args = array(
'post_type' => 'testimony',
);
$testimony = new WP_Query($args);
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( 0 !== $wp_query->current_post
&& 0 === $wp_query->current_post%3
&& $testimony->have_posts()
) {
$testimony->the_post();
echo 'inner-loop';
the_title();
echo 'inner-loop';
echo '<br>';
}
wp_reset_postdata();
the_title();
echo $wp_query->current_post;
echo '<br>';
}
}
You don’t need the loop counter. There is a counter built into WP_Query
, and you don’t need to be running that $testimony
query at every iteration of the outer loop.
The the_post
method will increment the Loop by one, so at each iteration the inner loop runs that, echo
s content and moves on.
There is obviously some debugging code in there. You can edit that out and replace it whatever you want.