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.
I think you are having a bad case of the old WordPress URL redirect.
Try adding this filter to stop it:
Custom post type numeric pagination -> http://designphiliconline.blogspot.in/2012/08/wordpress-custom-post-type-pagination.html
This will work with permalink set to default or postname
I had a problem with pagination in WordPress, and couldn’t fix it so I rolled my own extention of the WP_Query class -> MF_Query
Simply use MF_Query in place of WP_Query, and then use
$your_query->next("Next Page")
or$your_query->prev("Previous Page")
to add next and previous links (text has defaults, so no arguments required.It is required that you pass your arguments directly to the class initialisation as an array, as apposed to the various options you have with standard
WP_Query
.It’s a little hacky, but it works!!
This is the way I go to pass the paged variable into the CPT query for navigation, you can have different methods on doing this, but this the only one it has work for me using the WP_QUERY. And no need any plugin for navigation just standard navigation links.
You should place this line over here before you WP_QUERY
After you modify your loop file add this to your functions.php this is the variable that will work out the page your on.
You can also read this post is explaining the method of chaining templates this will fix pagination problem that we have to deal when involves custom queries.
http://wp.tutsplus.com/tutorials/custom-post-type-pagination-chaining-method/