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 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'.

Code:

    <?php
    /* 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() )
        the_post();
?>

<h1>
    <?php _e( 'Results', 'twentyten' ); ?>
</h1>
<div class="resultDetails">
    <p>Displaying all of our Events:</p>
</div>
<ul>
<?php 
    $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(); ?>
    </div>
</li>
<?php endwhile;?>
<nav class="navigation">

    <ul>

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

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

    </ul>

</nav>
</ul>

Any help would be greatly appreciated!

Thanks

share|improve this question
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 Oct 24 '11 at 20:37
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
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.