Articles of wp reset postdata

When should you use wp_reset_postdata vs wp_reset_query?

Seems like half the tutorials in the Codex use wp_reset_postdata() and half use wp_reset_query(). What’s the deal? Maybe Use both of them? What about rewind_posts()? I am asking for an answer based on facts, not on opinions.

Is there any need to use both wp_reset_postdata and wp_reset_query together?

Is there any need to use both wp_reset_postdata() and wp_reset_query() together? Is it a case that I would pick one of the two functions; is there any point in doing this after a query : wp_reset_postdata(); wp_reset_query();

Should 'setup_postdata()' be reset with 'wp_reset_postdata()'?

Starting with an example makes more sense, so here’s an example function: function seo_meta_tags() { global $post; if( is_singular() ) { setup_postdata( $post ); $description = str_replace( ‘… <a class=”read-more” href=”‘ . get_permalink() . ‘”>Cont. reading &rarr;</a>’, ‘…’, get_the_excerpt() ); wp_reset_postdata(); echo ‘<meta itemprop=”description” name=”description” content=”‘ . $description . ‘”>’; } } NOTE: The code […]

Is it necessary to reset the query after using get_posts()?

Is it necessary to reset the query after using get_posts() ? I have been looking at this page and I don’t see any reference to get_posts() … I can’t make it out for sure from this page either. I can’t see why it wouldn’t be necessary ( though on my test page it doesnt cause […]

Where should you reset postdata?

I’ve searched for this in the Q&A but I was unable to find it. When I read answers throughout the site I see wp_reset_postdata() placed in multiple areas with the have_posts() conditional and outside the conditional all together. When I read the documentation on wp_reset_postdata() all it states is: After looping through a separate query, […]

How does reset_postdata restore the post of the main query loop?

How does reset_postdata works? The docs say: restore the global $post variable of the main query loop after a secondary query loop using new WP_Query But in the class, it takes the “current” post of the current WP_Query instance, and set it as the global $post. So how does it restore the post of the […]

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

Reading some stuff about query_reset_postdata and query_reset_query makes me confused. For example: Is there any need to use both wp_reset_postdata and wp_reset_query together? http://www.poststat.us/properly-reset-wordpress-query/ Above states that you should only use query_reset_postdata() when using “separate queries”. In example2 there’s a comment: WP_Query( $args ) = wp_reset_postdata(); AND query_posts ( $args ) = wp_reset_query(); And really […]