How To Fix WordPress custom taxonomy pagination 404 error

In this post I’m going to explain how you can fix WordPress custom taxonomy pagination 404 error. Recently I had an issue with my custom post type taxonomy pagination. It was giving 404 “Page Not Found” when I tried to visit the second page by using the pagination like this:

pagination_demo-300x40

My intention was to use my taxonomy pagination like as above and access pages by the following URL:

http://example.com/cities/city/page/2/
http://example.com/cities/city/page/3/

Here in this URL above, “cities” is my custom post type and “city” is my custom taxonomy. The reason it was not working is because WordPress slug rules weren’t updated for my custom taxonomy. So after creating the new rewrite rules it is now working just like I wanted. Now Let’s see how I come up and fixed this issue.

First of all set up how many posts you want to show on each page at “Settings => Reading” inside your WP Admin. After that add this codes below to your functions.php file:

This will rewrite the slug and enable pagination (/page/2) view for all of your taxonomies. Use WordPress default query loop as you don’t need to modify it anymore to show posts. Now that you know this should work on all of your post types. If you want to be specific with your custom post types just update these variables like this below:

Enjoy 🙂

3 thoughts on “How To Fix WordPress custom taxonomy pagination 404 error”

  1. Awesome, thanks for the tip Jewel!

    The solution didn’t work out of the box, I had to trouble shoot and replace the & on line 17 by an actual amptersand. My line became
    $rules[$post_type_slug . ‘/’ . $term->slug . ‘/page/?([0-9]{1,})/?$’] = ‘index.php?’ . $term->taxonomy . ‘=’ . $term->slug . ‘&paged=’ . $wp_rewrite->preg_index( 1 );

Leave a Reply

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