Any help would be greatly appreciated!
I have a Custom Post Type 'video', with a taxonomy 'tax-video' and I'm looping through posts in the sub-taxonomy term 't-o-t-w'. I need to exclude the latest/most recent post.
I've been searching around for a couple hours trying different things, but still don't really even know where to start. Here's what I've tried, but it breaks the page:
<?php
//trying to get the recent post
$tip = get_terms('t-o-t-w','orderby=id&order=DESC&number=1');
$latest_tip = $tip[0]->ID;
$args = array(
'post_type' => 'video',
'tax_query' => array(
array(
'taxonomy' => 'tax-video',
'field' => 'slug',
'terms' => 't-o-t-w',
),
),
'posts_per_page' => '8',
//Trying to Exclude it here
'post__not_in' => array( $latest_tip ),
);
$query = new WP_Query( $args ); ?>
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
//code to be executed
<?php endwhile; endif; wp_reset_postdata(); ?>
post__not_in
, which can sometimes cause performance issues. Your wp_reset_postdata will always be called even if no postdata is set ( calls to the_post() ), move it inside the if statement just after the while loop. You may be able to avoid the query entirely by using the taxonomy archive that comes with WordPress, and the theme filetaxonomy-tax-video.php
, if so, usepre_get_post
to modify the query, rather than creating an whole new one