Rewrite rule regex help required

Question

Hoping you can help with this…

WE have a ‘serivces’ custom post type that allows a ‘service’ to have a parent ‘service’. Our custom rewrite rule works for top-level services but not child services.

The url structure would be something like the following where ‘test-service’ and ‘test-service-child’ are the post names:

  1. consultancy/test-service
  2. consultancy/test-service/test-service-child

Our existing rewrite rule is as follows:

add_rewrite_rule('^consultancy/(.*)/?', 'index.php?post_type=service&name=$matches[1]', 'top');

Can anyone suggest a modification that will get the post name from the end of the url? Eg in the case of the examples above it should match the following

  1. test-service
  2. test-service-child

Any help greatly appreciated. Thanks in advance,

Will

0
, , Will Fairhurst 7 months 0 Answers 96 views 0

Leave an answer