WordPress | wrap every two posts
$i = 0;
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php if ( $i % 2 == 0) { ?>
<div class="col_half nobottommargin">
<?php } ?>
//the post data
<?php if ( $i % 2 != 0 ) { ?>
</div>
<?php } ?>
<?php $i++; endwhile; // End Loop. ?>
<!-- added closing </div> for odd number of posts -->
<?php if ( $i % 2 != 0 ) {?>
</div>
<?php } ?>
<?php endif; wp_reset_postdata(); ?>