add_rewrite_rule – working fine but broken for pagination

Have you tried:

The main one:

add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]', 'top' );

For pagination

add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]&paged=$matches[3]', 'top' );

Out of curiousity, I replaced one of the ([^/]+) with the literal ‘type’ since that doesn’t seem to be a dynamic variable.

If the pagination doesn’t work, try switching the order of when it’s declared, i.e. before or after your other rewrite rules. Alot of issues have to do with what order they’re declared which effects which rule is run first.

Also, the Rewrite Rules Inspector plugin can be super helpful in helping you figure out which rewrite rules are being run for specific URLs.

Leave a Comment