How add pagination for custom post type?

Hello Everyone

If you are trying to add pagination on for your custom post type using “WP-PageNavi” plugin in your site then you have need to add custom post type query in wp_pagenavi() function after end of while loop

<?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'portfolio-type', 'post_status' => 'publish', 'posts_per_page' =>'5','paged'=>$paged ) );
    while ( $loop->have_posts() ) : $loop->the_post();
    $postIDD=get_the_ID();
?>
<article id="post-<?php echo $postIDD; ?>" <?php post_class(); ?>>
    <h6><?php the_title();?></h6>
    <strong>About :</strong>
    //$cont=$loop->post_content();
    $post_7 = get_post($postIDD);
    $cont = $post_7->post_content;
    echo strip_tags($cont); ?>
    <br><a target="_blank" href="<?php echo get_post_meta($postIDD,'wpcf-url',true); ?>">&nbsp;</a>    
</article>
<?php
endwhile; // end of the loop.
wp_pagenavi( array( 'query' => $loop ) ); //pagination
 ?>

Enjoy Code:!

4 Replies to “How add pagination for custom post type?”

  1. I’m amazed, I must say. Rarely do I come across a blog that’s both educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is something which too few men and women are speaking intelligently about. I am very happy that I found this in my search for something relating to this.

Leave a Reply

Your email address will not be published. Required fields are marked *