We have a section on the site, such as:
www.example.com/for-sale/category-name/
for-sale
is a WP page, however category-name
is dynamic and is what I wrote the below rewrite rule for.
add_rewrite_rule('for-sale\/([a-z-]+)\/?$', 'index.php?pagename=for-sale&search_slug=$matches[1]', 'top');
However, problems arise when the user needs to use the page
query var, if I try going to:
www.example.com/for-sale/category-name/?page=2
it get's rewritten to:
www.example.com/for-sale/2/
So completely strips out the category slug.
Is there a way I can get this to work?
...or preferably I would like to be able to use something like this:
www.example.com/for-sale/category-name/2/
So I tried adding this additional rewrite rule:
add_rewrite_rule('for-sale\/([a-z-]+)\/([0-9])+\/?$', 'index.php?pagename=for-sale&search_slug=$matches[1]&page=$matches[2]', 'top');
..but again, it redirected back to:
www.example.com/for-sale/2/
What am I missing here?