wp_reset_query() or wp_reset_postdata() after a custom query?

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.

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' => 'my_cpt',
     '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.