reset to main loop doesnt work
reset to main loop doesnt work
reset to main loop doesnt work
wp_reset_postdata() restores the post from main query, which you do not seem to be using here at all. So before final the_title() call you jump out all the way to that post. Your code seems to be tad problematic to me because both your outer and inner loops continuously rewrite $post global. If you move … Read more
You can save the $post in some temp variable and just set the $post back to the temp variable global $post; while ( have_posts() ) : the_post(); //Set up custom query $args = array( //Query args ); $custom_query = new WP_Query( $args ); //Custom query loop: while ( $custom_query->have_posts() ) : $custom_query->the_post(); // Save global … Read more
I believe the official stance is to not use WP_Query in the admin panel. There’a a trac ticket #18408 on this exact same issue. Here’s what Boone says: The root issue is that wp_reset_postdata() is designed to reset globals to match the main query. But in the case of post.php, there is no main query … Read more
As setup_postdata is messing with global variables that might be (most probably: are) used by other loops (including The Loop), you should always reset these variables to what they should be—according to the main query (i.e., what WordPress thinks the user wanted in the first place). In addition, setup_postdata is provided with (a reference to) … Read more
There’s no need to use them both. You should only use wp_reset_query(), if you modified query with query_posts() (which you should avoid). This function also call wp_reset_postdata() – http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/query.php#L95 So it’s better to use wp_reset_postdata() after running separate query.
It’s not in the documentation mainly because it’s an internal function, they weren’t expecting you to use or need it. have_rows() checks to see whether there is a currently active loop- if not, it creates a global with your repeater rows; if so, it picks up where you left off- then it lets you know … Read more
wp_reset_postdata() resets the value of the global $post variable to the post property of the main query, which will be whatever post the main query was last on. You would do this if you had used setup_postdata() or $query->the_post() on a custom query. Both of these replace the global $post variable so that functions like … Read more
WordPress uses global $post variable. This way you don’t have to pass post nor post_ID as param for functions. So you can call the_title() and WP knows which title should it show. This behavior works fine, if there is only one loop on the site. But if you create your own custom loops and iterate … Read more
Short version: As Tom J Nowell said, You shouldn’t cleanup if there’s nothing to clean Long version: However, if you put wp_reset_postdata() after (or outside) the loop, it would still work perfectly fine. I have used the function in various scenarios, including something like this: dynamic_sidebar( ‘main-sidebar’ ); wp_reset_postdata(); The reason was that some widget … Read more