Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
My answer would be the same as the comment on your other question. –  Milo Mar 13 '13 at 15:29
add comment

1 Answer

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); ?>
share|improve this answer
    
Please explain why that could solve the problem. –  toscho Mar 13 '13 at 15:37
    
based on wordpress.stackexchange.com/questions/20424/… –  Michael Mar 13 '13 at 16:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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