In WordPress loop, how do I check how many post have been looped through?
<p>My goal is to print some extra html,  after every four posts.</p>

<p>What is wrong with the following code </p>

<pre><code>&lt;?php while ( have_posts() ) : the_post(); ?&gt;
    &lt;?php wc_get_template_part( 'content', 'product' ); ?&gt;
    &lt;?php
        $posts = $wp_query-&gt;post_count;

        if ( $posts == 4 ) {
            echo '&lt;div class="clearfix"&gt;&lt;/div&gt;';
        }
    ?&gt;
&lt;?php endwhile; // end of the loop. ?&gt;
</code></pre>