I have a custom post type called 'doel'. I have made a page template to display all the doel items

In this page template I loop the 'doel' post type and after 6 of them, I want to have a pagination. Only, the pagination does not appear.

I started browsing on the internet and it seemed to be a common problem after version wp version 3.4

I tried some solutions from this site and the wp forums but none of them helped.

For Example, what I tried was adjusting the loop, so the pagination would be IN the loop, OUT of the loop or between endwhile and endif. Also I tried the wp pagenavi plugin and the original wp previous and next post links but none of them are working, so I think there is something wrong in my loop.

My code atm is:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array(
'post_type' => 'doel',
'posts_per_page' => 6,
'orderby'=> 'menu_order',
) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <div class="doel">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array('class' => 'featuredimg')); ?></a>
        <img class="logodoel" src="<?php the_field('logo_doelen'); ?>" />
        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <p><a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a></p>
        <a href="" class="doneerlink">Doneer nu</a>

<?php endwhile; ?><br class="clear" /> 
<?php wp_pagenavi(); ?>

2 Answers 2


Simply replace the wp_pagenavi(); by

    wp_pagenavi(array(  'query' => $loop) ); 
  • That doesn't work eighter, prints nothing :(
    – Maartje
    Jan 15, 2014 at 11:10
  • please try puting 'posts_per_page'='6' within quotes Jan 15, 2014 at 11:16

Your pagination call is in no way aware of your query, it cannot just know what you mean it to paginate.

You need to pass your query object to it:

<?php wp_pagenavi( array( 'query' => $loop ) ); ?>

See using wp_pagenavi() with custom queries for details.

  • It is working now :) I used the code from the link you gave me and adjusted it a little bit :)
    – Maartje
    Jan 16, 2014 at 9:29
  • For people who are also looking for this, what worked for me was: <?php $my_query = new WP_Query( array( 'posts_per_page' => 9, 'post_type' => 'doel', 'paged' => get_query_var('paged') ) ); while ( $my_query->have_posts() ) : $my_query->the_post(); ?> CONTENT <?php endwhile; wp_pagenavi( array( 'query' => $my_query ) ); wp_reset_postdata(); // avoid errors further down the page ?>
    – Maartje
    Jan 16, 2014 at 9:31

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.