【发布时间】:2011-06-23 08:36:39
【问题描述】:
这就是我所拥有的:
我正在编辑自定义分类页面。登陆页面时,页面查询会自动设置为返回我所在的自定义分类下的帖子列表。在该页面模板中,我运行此查询帖子:
query_posts(
array_merge(
array( 'post__in' => $_SESSION['lpoc_search_data'], 'orderby' => 'post__in' ),
$wp_query->query
)
);
我运行我的循环并且上面完成的查询运行良好。
<?php while (have_posts()) : the_post(); ?>
My Loop
<?php endwhile; ?>
但是在上面的循环中我做了另一个查询:
<?php $args = array('p' => $officeID, 'post_type' => "offices"); query_posts($args); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
//Inside secondary loop
<?php endwhile; ?>
<?php wp_reset_query(); ?>
如你所见,我使用 wp_reset_query();使上面的循环恢复到原来的状态。或者你会这么想。但是正在发生的事情是 wp_reset_query() 正在将查询重置为页面查询,而不是我在第一个代码块中所做的查询。为什么会发生这种情况?如何防止这种情况发生?
亲切的问候
斯科特
【问题讨论】: