你好@janoChen:
简单回答:否。
下面是函数的PHP代码wp_reset_query()
从…起/wp-includes/query.php
在WordPRess v3中。0.4以及随后调用的函数。您可以看到,它主要是关于修改全局变量。
当您使用new WP_Query($args)
您将把返回值从值分配给局部变量,因此,除非您正在做一些非常复杂的事情,以至于您已经知道这个问题的答案,否则不需要调用wp_reset_query()
:
function wp_reset_query() {
unset($GLOBALS[\'wp_query\']);
$GLOBALS[\'wp_query\'] =& $GLOBALS[\'wp_the_query\'];
wp_reset_postdata();
}
function wp_reset_postdata() {
global $wp_query;
if ( !empty($wp_query->post) ) {
$GLOBALS[\'post\'] = $wp_query->post;
setup_postdata($wp_query->post);
}
}
function setup_postdata($post) {
global $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages;
$id = (int) $post->ID;
$authordata = get_userdata($post->post_author);
$day = mysql2date(\'d.m.y\', $post->post_date, false);
$currentmonth = mysql2date(\'m\', $post->post_date, false);
$numpages = 1;
$page = get_query_var(\'page\');
if ( !$page )
$page = 1;
if ( is_single() || is_page() || is_feed() )
$more = 1;
$content = $post->post_content;
if ( strpos( $content, \'<!--nextpage-->\' ) ) {
if ( $page > 1 )
$more = 1;
$multipage = 1;
$content = str_replace("\\n<!--nextpage-->\\n", \'<!--nextpage-->\', $content);
$content = str_replace("\\n<!--nextpage-->", \'<!--nextpage-->\', $content);
$content = str_replace("<!--nextpage-->\\n", \'<!--nextpage-->\', $content);
$pages = explode(\'<!--nextpage-->\', $content);
$numpages = count($pages);
} else {
$pages = array( $post->post_content );
$multipage = 0;
}
do_action_ref_array(\'the_post\', array(&$post));
return true;
}
-迈克