Skip to content

Instantly share code, notes, and snippets.

@pixelstorm
Last active April 30, 2018 10:09
Show Gist options
  • Save pixelstorm/2bd9ddcdad9c0cee5cdd8ac54e925336 to your computer and use it in GitHub Desktop.
Save pixelstorm/2bd9ddcdad9c0cee5cdd8ac54e925336 to your computer and use it in GitHub Desktop.
paginaiton for custom post type
//set up the loop, in this case we are looping through projects custom post type
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$project_query = new WP_Query( array(
'post_type' => 'project',
'posts_per_page' => 2,
'paged' => $paged
) );
?>
//do the loop
<?php if ( $project_query->have_posts() ) : ?>
<?php while ( $project_query->have_posts() ) : $project_query->the_post();
//output content
endwhile; ?>
//output pagination links
<?php $big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'type' => 'list',
'current' => max( 1, get_query_var('paged') ),
'total' => $project_query->max_num_pages
) ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment