I'm pulling my hair out with this! The following code correctly inserts a div with row as the class every 2 posts. HOwever, when there's an even number of posts, it displays an extra empty div below. Can anyone help please?
Thanks!
<div class="row">
<?php
$connected = new WP_Query( array(
'connected_type' => '2-col-module_to_pages',
'connected_items' => get_queried_object(),
'nopaging' => true,
) );
if ($connected->have_posts() ) : while ($connected->have_posts()) : $connected->the_post(); ?>
<div class="tile">
<div class="wrapper">
<div class="content">
<h2><?php the_title();?></h2>
</div>
</div>
</div>
<?php $counter++;
if ($counter % 2 == 0 ) {
echo '</div><div class="row">';
}
endwhile; wp_reset_postdata(); endif; ?>
</div>