Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom taxonomy set as a "splash" on my front page, I would like to only display the latest one of these taxonomies as a splash, and any older ones to be returned to the loop and displayed as normal.

My code atm below displays the splash fine, but reproduces the splash again in the loop for some reason:

$args = array(
    'post_type' => 'post',
    'posts_per_page' => '1',
    'order_by' => 'date',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'theme',
            'field' => 'slug',
            'terms' => array ('text-image', 'just-image', 'just-text')
        )
    )
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();

Any help would be appreciated!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You should save the ID of the first post in a variable (e.g $splash_post_id) and in the next loop, use "post__not_in" => $splash_post_id , in the $args array.

$args = array(
    'post_type' => 'post',
    'posts_per_page' => '1',
    'order_by' => 'date',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'theme',
            'field' => 'slug',
            'terms' => array ('text-image', 'just-image', 'just-text')
        )
    )
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();
        $splash_post_id = get_the_ID();
          .......
          .......
    endwhile; 
endif;

$args = array(
     'post__not_in' => array($splash_post_id),
    'post_type' => 'post',
    'posts_per_page' => '10',
    'order_by' => 'date',
    'order' => 'DESC',
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();

          .......
          .......
    endwhile; 
endif;
share|improve this answer
    
How would I go about doing that? –  kallekillen Jan 31 '13 at 11:39
    
@kallekillen I edited the answer –  Waseem Abu Senjer Jan 31 '13 at 11:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.