Please help I got issues.
I got two page php templates...
https://gist.github.com/jcranny/9393553 - gallery.php (returns the 404 error on pages above 1)
https://gist.github.com/jcranny/9393602 - news.php (works fine on all paginated pages)
OK <strong>news.php</strong> works fine, all paginated pages work absolutely fine http://www.samlowes.com/core/news/ this is displaying posts.
But <strong>gallery.php</strong> works fine on page 1 only, and all other paginated pages return page 404!!! http://www.samlowes.com/core/gallery/ The only difference is that it is using a gallery post type.
I just did a test and swapped the post types in the templates wp_querys - and 'gallery' post-type works fine in <strong>news.php</strong> but the 'post' post-type returns 404 in the <strong>gallery.php</strong> template. wtf
But the templates are identical - how come one is working and one is not?
Please help.
Thanks
Josh
Francisco Javier Carazo Gil answers:
Try this code in your functions.php:
function fix_category_pagination($qs){
if(isset($qs['category_name']) && isset($qs['paged'])){
$qs['post_type'] = get_post_types($args = array(
'public' => true,
'_builtin' => false
));
array_push($qs['post_type'],'post');
}
return $qs;
}
add_filter('request', 'fix_category_pagination');
Josh Cranwell comments:
Tried it but does not fix.
Do I need to modify?
Hariprasad Vijayan answers:
Hello,
Try to install Category pagination fix plugin(http://wordpress.org/plugins/category-pagination-fix/)
Josh Cranwell comments:
Installed it, no change...
http://www.samlowes.com/core/gallery/page/2/
Hariprasad Vijayan comments:
okay. maker sure you are using flush_rewrite_rules(). will get error for custom post type pagination if you are not using this.
https://codex.wordpress.org/Function_Reference/flush_rewrite_rules
Josh Cranwell comments:
Bhavesh sorted it thank. Me being an idiot.
Thanks
Hariprasad Vijayan comments:
Glad to hear. :-)
Bob answers:
Generally this type of things happen when you use same name for "page" and "custom post type".
For example you have page named gallery and post type named gallery also.
or you have category or something else(tag,post) that use gallery slug and you have post type named gallery also
A very simple solution I'm using is: The page that lists the custom post types is called in plural (eg. products) and the actual post type name is in singular (eg. product). So they dont conflict and it's all fine.
Basically, you CANT have a PAGE and a CUSTOM POST TYPE with the same name. If you do, the permalink rewrite rules will get confused and trigger a 404.
one more thing have to you added following attribute when you register custom post type?
'rewrite' => array('slug' => 'gallery')
Can you provide us url which creates trouble?
Bob comments:
Check that if you have any slug which is like the custom post type slug.
There might be in Page, Post, Category if yes then try to change slug.
or change slug of your gallery post type.
Josh Cranwell comments:
Bhavesh Vaghela your second answer was the problem.
My page was called gallery and my post type was called gallery.
Fixed thank you.