Trying to understand if you should use wp_reset_query() or wp_reset_postdata() after a custom WordPress query’s loop? The answer is the latter.
1 answers
1
Use wp_reset_postdata() instead of wp_reset_query()
You should use wp_reset_postdata() straight after you close your custom query’s loop as per the example below.
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
while ( $loop->have_rows() ) : $loop->the_row();
// Do stuff
endwhile;
wp_reset_postdata();
The reasoning for this is that using wp_reset_postdata() after the loop closes, resets the $post variable back to the post’s main query accordingly.
— Support WizardAnswer 1