Wordpress wp_reset_query()或wp_reset_postdata()
我对此感到困惑,因此我举了一个例子:Wordpress wp_reset_query()或wp_reset_postdata(),wordpress,loops,Wordpress,Loops,我对此感到困惑,因此我举了一个例子: <ul class="prod"> <?php $woop = new WP_Query($wol); while ( $woop->have_posts() ) : $woop->the_post(); global $prod; ?> <h3><?php the_title(); ?></h3> <?php wooc
<ul class="prod">
<?php $woop = new WP_Query($wol);
while ( $woop->have_posts() ) : $woop->the_post(); global $prod; ?>
<h3><?php the_title(); ?></h3>
<?php woocommerce_template_loop_add_to_cart( $woop->post, $prod );?>
<?php endwhile; wp_reset_postdata();?>
</ul>
在本例中,我应该使用wp\u reset\u query()
还是wp\u reset\u postdata()
我的理解是,在每次使用Query\u posts()
的自定义wp\u Query()
和wp\u reset\u Query()
循环后,我都必须使用wp\u reset\u postdata()
就这么简单吗?您不应该使用
wp\u reset\u query()
,它仅用于在使用query\u posts()
时将$wp\u query
和全局post数据恢复到原始主查询
相反,当您想在使用
new wp\u query()
的辅助查询循环之后还原主查询循环的全局$post
变量时,您应该只使用wp\u reset\u postdata()您在示例中正确使用了此选项。您不应该使用wp\u reset\u query()
,它仅用于在使用query\u posts()
时将$wp\u query
和全局post数据还原到原始主查询
相反,当您想在使用new wp\u query()
的辅助查询循环之后还原主查询循环的全局$post
变量时,您应该只使用wp\u reset\u postdata()您在示例中正确使用了此选项。