I have two loops with one same WP_Query, I tried place wp_reset_postdata(); either right after endwhile; in each loop, or just once after all loops (like below), both seems to be working.
What is the correct way of doing it, and why?
<?php
$q = new WP_Query((array(
'cat' => 1,
'posts_per_page' => -1
)));
if ($q->have_posts()) :
while ($q->have_posts()) : $q->the_post();
// first loop
endwhile;
endif;
if ($q->have_posts()) :
while ($q->have_posts()) : $q->the_post();
// second loop
endwhile;
endif;
wp_reset_postdata(); // should reset be here or after endwhile; in each loop?
?>