WordPress custom post type pagination returns 404 page error

I created a custom post type that is the same name as a page of mine. I fixed that with custom code and that is working now:

'has_archive' => false,
'rewrite' => array(
'slug' =>'case-studies',
'with_front' => false 

But now when clicking a pagination link in my custom post type “case-studies” listing of posts (or enter a URL like www.beezer.com/case-studies/page/2), I get the 404 a page.

I have tried lots of custom code, including using Monkeyman Rewrite Analyzer but it doesn’t work.

function my_pagination_rewrite() {
    add_rewrite_rule('case-studies/([^/]+)?(:/([0-9]+))?/?$', 'index.php?category_name=case-studies&paged=$matches[1]', 'top'); 
} 

add_action('init', 'my_pagination_rewrite');

Can anyone help?

1 Answer

Firstly – please change ‘has_archive’ into ‘true’

'has_archive' => true

And could you please share more detail code? I mean code which creates CPT and archive page.

Archive from: https://stackoverflow.com/questions/59056935/wordpress-custom-post-type-pagination-returns-404-page-error

Posted in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *