Okay, after a lot of playing around, I found this:
- The regex it was matching (while skipping over my rule) was
practice-area/(.+?)(?:/([0-9]+))?/?$
- This had a
$matches
array of 2:parent-page/child-page
and anumber
that follows that, which is blank since there isn’t one in the URL I was trying to build. - Also the URL it was redirecting to was
index.php?post-type=$matches[1]&page=$matches[2]
. I didn’t realize thatpost-type
could be a query var key. So that’s what ultimately got me on the right path.
- This had a
- So I decided to directly copy that, but instead of looking for a number I look for any character
- I used
post-type/(.+?)(?:/(.+))?/?$
- This didn’t work because I ended up with
$matches[1] = parent-page
and$matches[2] = child-page/section-id
- I used
- So, with a bit more tweaking, and messing with the laziness of the capture groups, I came up with
post-type/(.+)/(.+?)/?$
, which successfully superseded the regex in (1) above.$matches[1] = parent-page/child-age
and$matches[2] = section-id
The final rewrite rule is:
add_rewrite_rule('post-type/(.+)/(.+?)/?$', 'index.php?post-type=$matches[1]§ion=$matches[2]','top');