• I searched for hours trying to figure out how to instantiate pagination for my custom portfolio post type. The code below is what I used to accomplish this. I am posting this because of how long it took me and how frustrating it was to get here. Hope this helps.

    – MAIN LOOP –

    <?php $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    		        //LOAD PORTFOLIO QUERY
    		        $args = array(
    				'post_type' 		=> 'portfolio',
    				'posts_per_page' 	=> 50,
    				'order'				=> 'DESC',
    				'paged' 			=> $paged
    				); 
    
    				$wp_query = new WP_Query( $args );
    
    		    	if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); 
    
    		        get_template_part( 'loop-wook' ); //PULL LOOP-PORTFOLIO.PHP
    
    		        endwhile; wp_reset_postdata(); endif; ?>

    I created a separate template for pagination named template-pagination.php.

    – TEMPLATE PAGINATION –

    <?php
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    $args = array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    	);
    
    echo paginate_links( $args ); ?>

    I then call the pagination after the last div in my loop file.

    – GET TEMPLATE PART –

    <div>
      - THE LOOP -
    </div>
    <?php get_template_part('template', 'pagination'); ?>

    From here you should be able to wrap the pagination in links or style the class names to get your pagination where you want it.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Type Pagination’ is closed to new replies.