Reputation: 21
Hey I have been trying to get pagination working on my custom post type - I have had some sort of success with this code here (below) however when I turn permalinks back onto the %postname% setting I get a 404 when I a click next page but on the default permalinks in works fine.
I have tried the solutions here but to no avail - http://wordpress.org/support/topic/pagination-with-custom-post-type-getting-a-404?replies=1#post-1616810
If anyone can help that would be brilliant.
<?php
$type = 'faqs';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$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();
$wp_query->query($args);
?>
<?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="faq-container">
<div class="faq-question">
<h1><?php the_title(); ?></h1>
</div>
<div class="faq-answer">
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">Read full answer →</a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Upvotes: 0
Views: 439
Reputation: 4110
Once I also faced this type of problem becouse I have a custom post type's name and page's slug the same.
In my case I had the custom post type "book" and then a page called "book" with the slug "book" to display the custom post type's posts.
However this causes conflict with WordPress's rewrite rules and as a result was triggering my 404 error.
The solution was simply to change the "book" page's slug to "books" or anything other than "book" actually.
may this help you....
Upvotes: 4