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

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;
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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