0

I'm currently running a wp_query like this:

<?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 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
0

try:

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

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.