Support » Fixing WordPress » Paging not working for custom loop

  • Cedric_89


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

    	$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; ?>
        	$wp_query = null;
    	$wp_query = $temp;

    Next/previous links in header.php:

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

    This here is the page with the code in question:

    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)
  • vtxyzzy


    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.