I have a site which has pages that show products (these aren't sold on the site, though, it's just informational).
Some categories have subcategories, so the URI for a subcategory archive page looks like this:
/products/category-1/category-1-child/
But some categories don't have any subcategories, so the URI for a product post in that category looks like this:
/products/category-2/product-name/
The issue I'm having is thatSo either the WPfirst URL rewriterworks and the 2nd one is having trouble telling which URL points to a subcategory404, or the second URL works and which points to a product post.
Asthe first one is 404, as either a subcategory name or a post slug can be in that third position in the URL,.
I can only seemsuspect that the WP's built-in process which resolves permalinks to get eitheran internal URL which has the relevant information in query vars, seems to be unable to tell whether the URL points to a subcategory or thea product post working at those URLsin a single-level category.
I've tried all sorts of settings using rewrite_rules_array
but I can only ever get one or the other working.
Here's what I have in the rewrite_rules_array
that works for posts but not subcategories, for example:
$new_rules['products/([^/]+)/([^/]+)/?$'] = 'index.php?product_category=$matches[1]&product=$matches[2]';
And here's a rule which works for a subcategory archive page, but fails on a single-level-category post:
$new_rules['products/([^/]+)/([^/]+)/?$'] = 'index.php?product_category=$matches[2]';
(Though this is also the default behaviour if I don't add anything.)
Note that the array key is the same for both URLs, as they both have the same URL format. I'm sure I'm missing something simple here!