add_rewrite_rule – working fine but broken for pagination

I’m having an issue with me rewrite rule works fine here:

example.com/resources/   
example.com/resources/articles/

but when i use pagination to the next page i get a 404 here:

Read More
example.com//resources/articles/page/2/   
example.com//resources/articles/page/3/  
example.com//resources/articles/page/4/

I was able to write two rewrite rules but now instead of getting a 404 page, the page refreshes with same content but URL changes here is my rewrite rules hopefully some one can help?

  add_rewrite_rule( 'resources/([^/]+)/([^/]+)/?', 'index.php?taxonomy=res_category&term=$matches[1]&post_type=$matches[2]', 'top');
//added for page turn on pagination 
add_rewrite_rule('resources/([^/]+)/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=res_category&term=$matches[1]&post_type=$matches[2]&paged=$matches[3]', 'top');  

thank you ahead for any help.

Related posts

2 comments

  1. You are checking for a fragment too much/missing on fragement. You should get rid of one ([^/]+)

    add_rewrite_rule('resources/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=res_category&term=$matches[1]&post_type=resources&paged=$matches[2]', 'top');
    
  2. I figured it out! I had too many parameters trying to match and had to replace “[^/]+” with “(.+?)” i was able to get this with just one rewrite rule here is the final code:

    add_rewrite_rule( 'resources/(.+?)(/page/([0-9]+))?/?$', 'index.php?taxonomy=res_category&term=$matches[1]&paged=$matches[3]', 'top');
    

    now the problem i have now i get a 404 on the post itself if i click on an article ??? any clue why??

Comments are closed.