When inside The Loop, I want to retrieve the current post count.
For example, after every 3 posts, I want to insert an ad.
So, how do I get the value of the loop count?
You can use the current_post member of the WP_Query object instance to get the current post iteration;
while ( have_posts() ) : the_post();
// your normal post code
if ( ( $wp_query->current_post + 1 ) % 3 === 0 ) {
// your ad code here
}
endwhile;
Note, if you're using this inside a function, you'll need to globalise $wp_query.
true because 0 modulus any real number is always 0. The ad code is being incorrectly inserted before your first post, fourth post, seventh post - etc. Updated code should read: ($wp_query->current_post + 1) % 3.