I'm trying to display the Next/Prev navigation buttons on my page which displays all of the pages within my 'events' custom post-type. The issue is that the buttons are not even displaying, but I have no idea why not. I have had this working with my Blog page posts, but I wonder whether there is something different I need to do with a custom post-type, considering that it's capability is set to 'page' instead of 'post'.


    /* Queue the first post, that way we know
     * what date we're dealing with (if that is the case).
     * We reset this later so we can run the loop
     * properly with a call to rewind_posts().
    if ( have_posts() )

    <?php _e( 'Results', 'twentyten' ); ?>
<div class="resultDetails">
    <p>Displaying all of our Events:</p>
    $paged = get_query_var('paged');
    $paged = ($paged) ? $paged : 1;
<?php $loop = new WP_Query( array( 'post_type' => 'events', 'posts_per_page' => -1, 'paged' => $paged ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<li class="resultItem">
    <?php if (has_post_thumbnail( $post->ID )): ?>
        <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/thumbs.php?src=<?php echo $image[0]; ?>&w=120&h=120&zc=1" alt="<?php the_title(); ?>" /></a>
    <?php endif; ?>
    <div id="resultText">
        <h2 class="redSubHeader"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
        <?php the_excerpt(); ?>
<?php endwhile;?>
<nav class="navigation">


        <li class="next-posts post-nav"><?php next_posts_link('Next') ?></li>

        <li class="prev-posts post-nav"><?php previous_posts_link('Prev') ?></li>



Any help would be greatly appreciated!


  • 1
    After a quick look, i'd say it comes from the "posts_per_page" argument set to -1 which will show all of the posts of one page, therefore restricting the pagination. Try a small number to see what's happening and let me know.
    – kevin
    Commented Oct 24, 2011 at 20:37

1 Answer 1


next_posts_link() and previous_posts_link() use the global $wp_query->max_num_pages to determine if there are more pages. since you're using a new instance of WP_Query, the $wp_query global does not relate to this new query.

Try explicitly passing $loop->max_num_pages to the function:

next_posts_link( 'Next' , $loop->max_num_pages );

or if you're not using the original query, call query_posts() with your arguments instead of creating a new WP_Query instance.

EDIT - also, as @kevin mentioned, posts_per_page set to -1 will load all posts, so you'd have to change that as well for it to paginate.

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.