• I’ve gone through several examples on how to do paging for a custom loop, yet I can’t get the next/previous links to show up with the following code in archive-event.php.
    (The plug-in used is Event Organiser, so I suppose the post_type is registered properly.)

    <?php
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$temp = $wp_query;
    	$wp_query= null;
    
    	$wp_query = new WP_Query( array( 'post_type' =>'event', 'posts_per_page' => 1,  'paged' => $paged ) );
    ?>
    
    <?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    <!-- The Loop -->
    <?php endwhile; endif; ?>
    
    <?php
        	$wp_query = null;
    	$wp_query = $temp;
    	wp_reset_query();
    ?>

    Next/previous links in header.php:

    <div class="next-post-link paging svg">
    	<?php next_posts_link('', '0') ?>
    </div>
    <div class="previous-post-link paging svg">
    	<?php previous_posts_link('', '0') ?>
    </div>

    This here is the page with the code in question: http://allesaffen.sg/?post_type=event

    There are two event posts, with paging set to 1, the next post link should actually show up but doesn’t. When I enter -1 all event posts are showing up as expected.

Viewing 1 replies (of 1 total)
  • AFAIK, previous/next_posts_link() only works with query_posts(), not with WP_Query. Try saving the current query and using query_posts() instead of WP_Query().

Viewing 1 replies (of 1 total)
  • The topic ‘Paging not working for custom loop’ is closed to new replies.