[wp-trac] [WordPress Trac] #12320: Invalid call to wp_reset_query() inside Recent Posts widget

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 25 15:40:35 UTC 2010


#12320: Invalid call to wp_reset_query() inside Recent Posts widget
--------------------------+-------------------------------------------------
 Reporter:  michelwppi    |       Owner:  azaozz              
     Type:  defect (bug)  |      Status:  new                 
 Priority:  normal        |   Milestone:  3.0                 
Component:  Widgets       |     Version:  2.9.2               
 Severity:  normal        |    Keywords:  has-patch query loop
--------------------------+-------------------------------------------------

Comment(by filosofo):

 Replying to [comment:11 michelwppi]:
 > BUT is the call is before (''by example just after the call of
 get_header()'') and if the default query (home by example) is completed
 (via a filter) by a '''query_posts()''' call (by example to affine query
 according detected browser), the unwished big reset cancel this query
 addition and the main loop will begin with the very first query.[[BR]]

 OK, so you're saying the problem occurs in a situation like this?

 {{{

 query_posts(/* some custom arguments */);

 get_sidebar(); /* here the recent posts widget appears */

 while (have_posts() ) : /* now the Loop starts */

 }}}

 If so, the main problem is that the theme is querying the wrong way.
 `query_posts` should be called immediately before its intended Loop, and
 certainly not have another template appear between it and the Loop.

 A better way to handle the main request query is to hook into the $wp
 object, for example at the 'parse_request' action hook.

 > In more general terms, a widget must not interfere with his environment
 especially shared global vars.

 That's probably a good idea for core, but many plugins and themes violate
 this.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12320#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list