I'm confused about an example from the docs:
<?php
// The main query.
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_title();
the_content();
endwhile;
else :
// When no posts are found, output this text.
_e( 'Sorry, no posts matched your criteria.' );
endif;
wp_reset_postdata();
/*
* The secondary query. Note that you can use any category name here. In our example,
* we use "example-category".
*/
$secondary_query = new WP_Query( 'category_name=example-category' );
// The second loop. if ( $secondary_query->have_posts() )
echo '<ul>';
while ( $secondary_query->have_posts() ) :
$secondary_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
?>
Isn't the first wp_reset_postdata()
completely redundant? Before querying $post
, the secondary query overwrites it anyways right? Is there ever a case where it makes sense to call wp_reset_postdata()
after the main loop?