我对此感到困惑,所以我问了一个例子:
<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_reset_query()还是wp_reset_postdata()?
我所理解的是,我必须在每个自定义WP_Query()之后使用WP_Query(),在使用query_posts()的每个循环之后使用wp_reset_query()。
就这么简单吗?
发布于 2016-07-26 16:58:27
您不应该使用wp_reset_query(),它只用于在使用query_posts() (您should never use)时将$wp_query和全局post数据还原到原始主查询。
相反,您应该只在希望在使用wp_reset_postdata()的辅助查询循环之后恢复主查询循环的全局$post变量时使用new WP_Query()。在您的示例中正确使用了此方法.
https://stackoverflow.com/questions/38595355
复制相似问题