Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Pagination not working on one template - but works on another?! WordPress


Please help I got issues.

I got two page php templates... - gallery.php (returns the 404 error on pages above 1) - news.php (works fine on all paginated pages)

OK <strong>news.php</strong> works fine, all paginated pages work absolutely fine this is displaying posts.

But <strong>gallery.php</strong> works fine on page 1 only, and all other paginated pages return page 404!!! 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.


Answers (3)


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
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:


Try to install Category pagination fix plugin(

Josh Cranwell comments:

Installed it, no change...

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.

Josh Cranwell comments:

Bhavesh sorted it thank. Me being an idiot.


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.