0

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!

1 Answer 1

1

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;
2
  • How would I go about doing that? Jan 31, 2013 at 11:39
  • @kallekillen I edited the answer Jan 31, 2013 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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