Wordpress wp_reset_postdate未按预期重置
我有一个Wordpress功能,在我的站点的两个页面中使用,主页和分类存档。虽然这段代码在分类归档上工作得很好,但主页似乎存在wp_reset_postdata()问题-但我不知道如何修复它。已经尝试了wp_reset_query(),但似乎没有任何不同 下面的代码输出特定类别内的帖子列表(在本例中,我只是输出ID)。我有一个单独的查询,检查一篇文章是否被“固定”。如果有,则嵌套在查询的位置1(因此有效地将post输入到数组输出中) 如果有一个“钉住”的职位,这是输出Wordpress wp_reset_postdate未按预期重置,wordpress,while-loop,postdata,Wordpress,While Loop,Postdata,我有一个Wordpress功能,在我的站点的两个页面中使用,主页和分类存档。虽然这段代码在分类归档上工作得很好,但主页似乎存在wp_reset_postdata()问题-但我不知道如何修复它。已经尝试了wp_reset_query(),但似乎没有任何不同 下面的代码输出特定类别内的帖子列表(在本例中,我只是输出ID)。我有一个单独的查询,检查一篇文章是否被“固定”。如果有,则嵌套在查询的位置1(因此有效地将post输入到数组输出中) 如果有一个“钉住”的职位,这是输出 0: 13402 1: 1
0: 13402
1: 10619
1: 171 <- this is the ID of the homepage - it should be ID #13383
2: 13409
3: 13397
4: 13361
5: 13332
6: 10886
7: 10884
8: 10862
9: 10795
0:13402
1: 10619
1:171我自己设法弄明白了这一点
if ( $pinnedID ) {
$backup=$post;
$wpb_pinned_content_query = new WP_Query($innerargs);
while ( $wpb_pinned_content_query->have_posts() ) : $wpb_pinned_content_query->the_post();
echo $count . ": " . get_the_ID();
echo "<br/>";
endwhile;
$post=$backup;
if($pinnedID !== get_the_ID()) {
echo $count . ": " . get_the_ID();
echo "<br/>";
}
}
if($pinnedID){
$backup=$post;
$wpb\u pinted\u content\u query=新的WP\u query($innerargs);
而($wpb_pinted_content_query->have_posts()):$wpb_pinted_content_query->the_post();
echo$count。“:”。获取_ID();
回声“
”;
结束时;
$post=$backup;
如果($pinnedID!==获取\u ID()){
echo$count。“:”。获取_ID();
回声“
”;
}
}
通过内联声明辅助查询,然后将全局$post存储到备份变量中,我可以再次访问原始$post,而无需调用wp_reset_postdata()
0: 13402
1: 10619
1: 171 <- this is the ID of the homepage - it should be ID #13383
2: 13409
3: 13397
4: 13361
5: 13332
6: 10886
7: 10884
8: 10862
9: 10795
if ( $pinnedID ) {
$backup=$post;
$wpb_pinned_content_query = new WP_Query($innerargs);
while ( $wpb_pinned_content_query->have_posts() ) : $wpb_pinned_content_query->the_post();
echo $count . ": " . get_the_ID();
echo "<br/>";
endwhile;
$post=$backup;
if($pinnedID !== get_the_ID()) {
echo $count . ": " . get_the_ID();
echo "<br/>";
}
}