I’ve written a WordPress plugin which looks at a list of brand names and dumps out an ordered list of the letters that they start with e.g. A B C D ….
When the user clicks on any given letter it lists the brand names starting with that letter e.g. Abus, ABike, Animal etc
The intention is then for the user to click on a brand name and be shown a list of items by that brand spread over several pages.
The url structure would therefore be:
http://www.domain.com/brands/A/Abus/1
http://www.domain.com/brands/B/Bontrager/1
etc
Because this is in WordPress trying to get my head around the regex that needs to go into the add_rewrite_rule. I can get it to match the first part (the /A/ or /B/ in the examples above) by doing this:
add_rewrite_rule('brands/?([^/]*)', 'index.php?pagename=brands&brand_letter=$matches[1]&brand_name=$matches[2]&page=$matches[3]
but I can’t get it to match the brand name itself nor the page number. Note that the brand name and number won’t always be in the url. The format is:
/brands {always} / brand_letter {always} / brand_name {sometimes} / page number {occasionally}
Can somebody please help me?
Change your regex to: