I'm currently running a wp_query like this:

            $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 then have some pagination at the bottom as such:

<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>

Say I have 11 posts that the query would return but one of them has the id of '3'. This means that I have 10 total posts and should return a number of 'next' links. For whatever reason at the end of those pages, there will be a 'next' link that links to a page that is blank.

I believe this empty page is the post I'm attempting to exclude with 'post__not_in'.

How can I exclude posts from my wp_query and still have accurate pagination?


1 Answer 1



<?php next_posts_link('Next Page &raquo;', $the_query->max_num_pages); ?>
<?php previous_posts_link('&laquo; Previous Page', $the_query->max_num_pages); ?>

Your Answer

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

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