Excluding posts with accurate pagination in wp_query
-
Hi there,
Currently I have a wp_query that I am excluding some posts from using the post__not_in parameter. The code is as follows:
<?php $the_query = new WP_Query( array( 'post_type' => 'photos', 'posts_per_page' => '2', 'post__not_in' => array(3), 'paged' => $paged ) ); ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?>
I am excluding a post with the id of 3. Well what is happening is that say I have 5 posts. This means that I should see the first two posts, click next, see the following 2. Done.
But for whatever reason when I am on page two, viewing the last two posts, I also see a link to view the next page. Problem is since I excluded that post, nothing shows up on the last page. I suspect wp is attempting to show post 5 with the id 3 which I am trying to exclude.
Is it possible to somehow not have the next post link show up? I am currently using the following for pagination:
<?php next_posts_link(); ?> <?php previous_posts_link(); ?>
Any help would be greatly appreciated. Open to all ideas.
- The topic ‘Excluding posts with accurate pagination in wp_query’ is closed to new replies.