Skip to content

Instantly share code, notes, and snippets.

@bepatrickdavid
Created April 14, 2016 08:00
Show Gist options
  • Save bepatrickdavid/df21915e7c41145941791f5bf88a0ee8 to your computer and use it in GitHub Desktop.
Save bepatrickdavid/df21915e7c41145941791f5bf88a0ee8 to your computer and use it in GitHub Desktop.
WP: Pagination custom post types
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( array (
'post_type' => 'offer',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
) );
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
//all what you need to show
<?php endwhile; ?>
<?php if(sizeof($the_query->posts) >= 9): ?> // based on settings of reading setting (number of post max show in blog)
<div class="nav-left"><?php next_posts_link(__('Older Entries','theme'), $the_query->max_num_pages) ?>
<div class="nav-right"><?php previous_posts_link(__('Newer Entries','theme')) ?></div>
<?php wp_reset_postdata(); ?>
<?php endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment