在运行第一个查询的循环时,只需将ID收集到一个数组中。示例:
// define your first query\'s arguments
$args1 = array(
... your first query args
);
$query1 = new WP_Query($args1);
while ( $query1->have_posts() ): $query1->the_post();
// this is your loop. Do whatever you want here
// add this in the loop to collect the post IDs
$exclude_posts[] = $post->ID;
endwhile;
// define your second query\'s arguments
$args2 = array(
\'post__not_in\' => $exclude_posts,
... rest of your parameters
);
$query2 = new WP_Query($args2);
while ( $query2->have_posts() ): $query2->the_post();
// this is your second loop. Do whatever you want here
endwhile;
wp_reset_postdata();