Wordpress custom post type pagination

Joe picture Joe · Jul 24, 2010 · Viewed 7.1k times · Source

I am trying to get pagination working with the wp pagenavi plugin and a custom post type (portfolio page) in WordPress and I am having no luck.

Here is a stripped down version of my portfolio page:

<?php get_header(); ?>

<?php
  $type = 'portfolio';
  $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 1,
    'caller_get_posts'=> 1
  );
  $temp = $wp_query;  // assign original query to temp variable for later use   
  $wp_query = null;
  $wp_query = new WP_Query($args); 
?>

<?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
...
<?php endwhile; else : ?>
...
<?php endif; ?>

<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    $wp_query = null; $wp_query = $temp; ?>

<?php get_footer(); ?>

I have my permalinks set to:

/%postname%/

and I have re-saved them.

When I got to page two of my portfolio, I get a 404 page. Any idea why this is happening?

Thanks for the help.

Answer

Malte Schulze-Boeing picture Malte Schulze-Boeing · Sep 4, 2013

I think you are having a bad case of the old WordPress URL redirect.

Try adding this filter to stop it:

add_filter('redirect_canonical','my_disable_redirect_canonical');

function my_disable_redirect_canonical( $redirect_url ) {
    if ( is_single( 'portfolio' ) )
    $redirect_url = false;
    return $redirect_url;
}