I’m trying to work out how to exclude posts used in the first four custom queries in the last typical query.. haven’t been able to find anything that will explain how to do this clearly.
My First four loops:
<?php
// Loop 1
$first_query = new WP_Query('category_name=funding&showposts=1'); // select category
$ids = array();
while($first_query->have_posts()) : $first_query->the_post(); ?>
<?php the_title(); ?></br>
<?php endwhile;
// Loop 2
$second_query = new WP_Query(array('post__not_in' => $ids,'category_name' => 'industry','posts_per_page' => 1)); // select category
while($second_query->have_posts()) : $second_query->the_post();
$ids[] = get_the_ID(); ?>
<?php the_title(); ?></br>
<?php endwhile;
// Loop 3
$third_query = new WP_Query(array('post__not_in' => $ids,'category_name' => 'open-consultations','posts_per_page' => 1)); // select category
while($third_query->have_posts()) : $third_query->the_post();
$ids[] = get_the_ID(); ?>
<?php the_title(); ?></br>
<?php endwhile;
// Loop 4
$fourth_query = new WP_Query(array('post__not_in' => $ids,'category_name' => 'policy','posts_per_page' => 1)); // select category
while($fourth_query->have_posts()) : $fourth_query->the_post();
$ids[] = get_the_ID(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
A typical WordPress query that I want to remove repeating posts from:
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb', array('class' => 'alignleft')); } ?></a>
<strong style="float:right;"><?php the_time('l, F jS, Y') ?></strong>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<hr>
<?php endwhile; ?>
<?php wp_pagenavi(); ?> <!-- Pagination -->
<?php endif; ?>
You have already figured it out but I will post an answer anyway for others.
To alter a Query, that has already been set, the easiest way is to use query_posts().
Note this will only work if run before the loop.