Pagination Custom post type

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:

<?php
$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',
'paged'=>$paged
) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>


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

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

2 Answers
2

Simply replace the wp_pagenavi(); by

if(function_exists('wp_pagenavi')) 
{
    wp_pagenavi(array(  'query' => $loop) ); 
    wp_reset_postdata(); 
}

Leave a Comment