0
我已经得到了在同一页上的两个循环的以下代码。多个Wordpress循环 - 第二个循环重复相同的帖子
我的问题是不管如何过滤帖子第二个循环不按预期方式工作。第一个循环显示正确的帖子,第二个循环只显示重复自己的同一个帖子。我已经阅读了多篇关于多重循环的文章,但无法弄清楚。任何想法,我要去错了吗?
$args1 = array(
'post_type' => array('post', 'diary'),
'meta_key' => 'custom-date',
'orderby' => 'meta_value',
'order' => 'asc',
);
$args2 = array(
'post_type' => 'bio',
'order' => 'asc');
// The Query
$the_query = new WP_Query($args1);
// The Loop
while ($the_query->have_posts()) {
$the_query->the_post();
get_template_part('content-1', get_post_format());
}
wp_reset_postdata();
$query2 = new WP_Query($args2);
// The 2nd Loop
while($query2->have_posts()) {
$query2->next_post();
get_template_part('content-2', get_post_format());
}
不是一个答案,但是这可能帮助:什么时候你应该使用WP_Query VS query_posts()VS get_posts()](HTTP ://wordpress.stackexchange.com/q/1753/12615)。此外,WPSE的研究还有很多涵盖[多重循环]的主题(http://wordpress.stackexchange.com/search?tab=votes&q=%22multiple%20loops%22%20is%3aquestion)。 – brasofilo