Page not found (404) on CPT / taxonomy page 2

Hi Guys,

Been pulling my hair out with this… basically I have a custom post type (videos) and a custom taxonomy (videos_category) which uses a template taxonomy-videos_category when I set the page to only show 5 videos, the pagination to show the next page of videos throws a 404. I.E
/videos/introduction/page/2.

I know it’s not directly a Sage issue, but just wondering what best practice to handle this in Sage or at all :S i’m stumped… do I need to make a new Wp-query?? I have no idea :frowning:

Pagination can be a big old mess. When you say “set the page to only show 5 videos” are you talking about this setting?
image
Or are you using pre_get_posts or something to adjust how many posts are displayed? If you’re using a filter or action to adjust the number of posts displayed, you often need to make sure you’re modifying some other…stuff…or pagination will stop working right. If you are using filters/actions, posting some of your code might help diagnose.

Otherwise, I feel a little silly saying this but…have you refreshed your permalinks?

Haha yeah I refreshed the permalinks. And you’re right, I did change the post count in the admin, just to test.

Another way I tried getting this to work was just creating an archive template and making a new Wp-query call etc… rather than chucking all my code here, I asked a similar question here that has a fair chuck of my code: https://wordpress.stackexchange.com/questions/288630/custom-post-type-and-custom-taxonomy-404-on-page-2

I didn’t set any filters… because I wasn’t having much luck I thought hey maybe I can just create a taxonomy-template and it will figure it out :stuck_out_tongue: so naive haha

Hey @alwaysblank I actually managed to find the 2nd page, it’s /videos/introduction?paged=2, so I guess I just need to do a rewrite or something to change ?paged=2 to page/2 ? soooo close, I think :stuck_out_tongue:

So after many trials and errors, I found I had to create a specific rewrite rule to go into my filters.php, one that handles post type ‘videos’ and the category (taxonomy) ‘videos_category’:

add_filter('init', function() {
    add_rewrite_rule( 
        '^videos/([^/]*)/([^/]*)/(\d*)?',
        'index.php?videos_category=$matches[1]&p=$matches[2]&paged=$matches[3]',
        'top' 
     ); 
});

I also found this plugin to be really helpful for viewing my rewrite rules: https://wordpress.org/plugins/rewrite-rules-inspector/

1 Like

I have the same issue, only on my end the custom taxonomy is not on a custom post type, it’s just on the standard post. Any idea what I need to do?