Hello,
I have encountered an interesting issue related to custom post type pagination that I cannot seem to resolve on a clients website - before you jump to conclusions, yes I have setup my rewrite correctly so that the custom post type is not the same name as the page label).
The issue is that my last page pagination is returning a 404.
For example myurl.com/page/1 , myurl.com/page/2 work fine then when I navigate to the last page myurl.com/page/3 I get a 404.
Here is a link to the page containing the issue:
http://www.eatyourkimchi.com/kpopcharts
The following is my custom post type init code:
function kpopcharts_custom_type_init() {
$labels = array(
'label' => __('kpopcharts'),
'singular_label' => __('kpopchart'),
'menu_name' => 'KPopChart'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'kpopcharts','with_front' => FALSE),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments', 'page-attributes','custom-fields', 'simple-video', 'p75-video-posting')
);
register_post_type('kpopchart',$args);
}
The following is my post query:
global $query_string, $kpopchart_query, $query;
$num_per_page = get_option('kpopchart_videos_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$position = (($paged - 1) * $num_per_page)+1;
if($_GET['sort_by'] == 'date'){
$order = ($_GET['order'] == 'ASC') ? $_GET['order'] : 'DESC';
$kpopchart_query = new WP_Query(array('post_type' => array('kpopchart'),
'orderby' => 'date',
'order' => $order,
'posts_per_page' => $num_per_page,
'paged' => $paged
));
} else {
$kpopchart_query = new WP_Query( array('post_type' => array( 'kpopchart' ),
'meta_key' => 'kpopchart_time_decay',
'orderby' => 'meta_value_num' ,
'order' => 'DESC',
'posts_per_page' => $num_per_page,
'paged' => $paged
));
}
And finally my pagination:
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $kpopchart_query->max_num_pages
) );
?>
Here is also a link to the pastebin (for those of you who enjoy pretty syntax highlighting: http://pastebin.com/KLVKXcqW
I apologize for the lengthy post - any help would be greatly appreciated.
Thank you!