[wp-trac] [WordPress Trac] #12320: Obscur wp_reset_query() function inside widget Recent Posts
WordPress Trac
wp-trac at lists.automattic.com
Sun Feb 21 13:42:58 UTC 2010
#12320: Obscur wp_reset_query() function inside widget Recent Posts
--------------------------+-------------------------------------------------
Reporter: michelwppi | Owner: ryan
Type: defect (bug) | Status: new
Priority: high | Milestone: Unassigned
Component: Query | Version: 2.9.2
Severity: normal | Keywords: query, loop, default widget
--------------------------+-------------------------------------------------
'''Description:'''
When adding Recent posts widget in sidebar of a home page modified by a
'''query_posts''' limiting to one cat. or other features, the loop result
of posts is not the attended one but the original default home query.
The ''recent posts widget'' in defaut-widgets.php contains a curious line:
{{{
wp_reset_query(); // Restore global post data stomped by the_post().
}}}
The Query.php contains this function with his "obscure" comment:
{{{
/**
* Destroy the previous query and setup a new query.
*
* This should be used after {@link query_posts()} and before another
{@link
* query_posts()}. This will remove obscure bugs that occur when the
previous
* wp_query object is not destroyed properly before another is setup.
*
* @since 2.3.0
* @uses $wp_query
*/
function wp_reset_query() {
}}}
With this resetting approach and - not with temporay backup and restore -
when, in loop in loop, sharing global vars as $wp_query or $wp_the_query,
it introduces unwanted side effects.
'''Temporary workaround:'''
Around the ''sidebar top'' box, needs to add these temp vars:
{{{
global $wp_the_query, $wp_query;
$tmp_query = $wp_query;
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar
top')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; $wp_the_query = $tmp_query; $wp_query = $tmp_query;
}}}
with the limit of only one ''recent posts'' widget in one sidebar box.
Don't hesitate to question me.
NOTE: In our [http://dev.xiligroup.com/xili-language/] plugin, we decide
to create a new like widget without this 'obscur' reset function
''wp_reset_query'' and added of other features for multilingual website.
Best regards, Michel of [http://dev.xiligroup.com]
--
Ticket URL: <http://core.trac.wordpress.org/ticket/12320>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list