So, first up, I don’t believe that you need a rewrite tag in this situation, so you can omit that.
The issue, I believe, with the remaining code is that your rewrite rule is only capturing 1 match (because there’s only one set of ()
), so subpage
isn’t receiving a value. Additionally, your rule seems to exclude any posts of your post type ( because of the . Actually, it seems to exclude any URLs where the post name begins with any of the letters ^
)p
,o
,s
,t
,_
,t
,y
,p
,e
.
I believe your rewrite rule should be:
add_rewrite_rule( 'post_type/([^/]+)/([^/]+)/?', 'index.php?name=$matches[1]&subpage=$matches[2]', 'top' );
Then you just need to make sure that in your template you’re accessing the subpage value correctly. $_GET['subpage']
will no longer work. Instead you need to use get_query_var( 'subpage' )
.
Also make sure you re-save your Permalinks settings.