You can simply build an array of ID’s of posts from the loops and then just exclude those posts from the following set of queries
I don’t know your exact structure, but here is a very basic idea (Requires PHP5.4+ due to short array syntax ([]
), for older versions, change back to old array syntax (array()
))
// Define the variable to hold posts
$remove_duplicates = [];
// define and run our first query
$args1 = [
// All your arguments for this query
];
$loop1 = new WP_Query( $args1 );
if ( $loop1->have_posts() ) {
while ( $loop1->have_posts() ) {
$loop1->the_post();
// Build our array of ID's to exclude from other query
$remove_duplicates[] = get_the_ID();
// Rest of your loop
}
wp_reset_postdata(); // VERY VERY IMPORTANT
}
// Define our second query and exclude posts from the first
$args2 = [
'post__not_in' => $remove_duplicates, // Remove posts from from $loop1
// All your arguments for this query
];
$loop2 = new WP_Query( $args2 );
if ( $loop2->have_posts() ) {
while ( $loop2->have_posts() ) {
$loop2->the_post();
// Rest of your loop
}
wp_reset_postdata(); // VERY VERY IMPORTANT
}