[wp-trac] [WordPress Trac] #11461: When creating a new WP_Query, running the_post() on the new object resets global $post
WordPress Trac
wp-trac at lists.automattic.com
Wed Dec 16 18:53:17 UTC 2009
#11461: When creating a new WP_Query, running the_post() on the new object resets
global $post
--------------------------+-------------------------------------------------
Reporter: bsdeluxe | Owner: ryan
Type: defect (bug) | Status: new
Priority: normal | Milestone: Unassigned
Component: Query | Version:
Severity: normal | Keywords: the_post, wp_query, scope, post
--------------------------+-------------------------------------------------
This happens when running multiple loops in a page. If a new WP_Query
object is created, $post should only be changed within the scope of that
object, right?
To replicate:
{{{
// in a template called from a page
echo $post->ID; // the ID of the page
$new_obj = new WP_Query();
$new_obj->query("some valid querystring");
if ($new_obj->have_posts()) : while ($new_obj->have_posts()) :
$new_obj->the_post();
// .. do your loop stuff
endwhile; endif;
echo $post->ID; // not the same as the first one
}}}
Suggested patch attached.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11461>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list