WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Anyone here see why my pagination won't work? I can get "previous page" to show up, but when navigating to "page-2", the content will stay identical to the content on "page-1".

Template Name: Generic Trips Template
<?php get_header(); ?>

        <?php get_template_part( "beforeloop", "page" ) ?>
                                    <?php $types = $post->post_name; ?>

 <?php if (have_posts()) : ?>
     <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 'trips', 'types' => $types, "posts_per_page" => 5)); ?>
        <?php while (have_posts()) : the_post(); ?>

                        <article id="post-<?php the_ID(); ?>" class="post">


<?php endwhile; ?>

<?php if(function_exists('wp_pagenavi')) : ?>
                           <div class="pnavi">
            <?php wp_pagenavi(); ?>
        <?php else : ?>
            <div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries')); ?></div>
            <div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')); ?></div>
        <?php endif; ?>

<?php endif; wp_reset_query(); ?>

                  <?php get_template_part( "afterloop", "page" ) ?> 

<?php get_footer(); ?>
share|improve this question
possible duplicate of query_posts and pagination, still stuck after much research – Chip Bennett Jun 7 '12 at 14:01
Please search the site before posting new questions. This particular question has been asked over and over and over again... – Chip Bennett Jun 7 '12 at 14:02
@ChipBennett : none of the answers I found this far solved my specific problem. – WouterB Jun 7 '12 at 14:32
@WouterB Explain in detail what you have tried already. – toscho Jun 7 '12 at 19:18
up vote 1 down vote accepted

Don't use query_posts!

As Eugene pointed out, you omitted the paged variable. However, even with that in you can get unexpected behaviour. As illustrated by the various questions we get on query_posts and pagination:

share|improve this answer

You have to add paged argument to query_posts call. It should look like this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        'post_type' => 'trips', 
        'types' => $types, 
        'posts_per_page' => 5,
        'paged' => $paged,
    ) );

Read more about WP_Query in codex, especially pagination section.

share|improve this answer
@EugeneManilov Good catch. Unfortunately that didn't help. – WouterB Jun 7 '12 at 14:37

Your Answer


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.