add_rewrite_endpoint( 'changelog', EP_ROOT );
Will add the endpoint, changelog
, which you can then check on template_redirect
hook.
On match the query variables ( $wp_query->query
) array should contain key changelog
containing whatever comes after the /
in value. So for URL example.com/product1/changelog/5
you would have a query variable named changelog
with the value 5
.
If there is nothing after endpoint then variable will be present, but contain empty string. Note that get_query_var()
won’t work for such use since it is hardcoded to return empty string if query var is not set at all.
It may be enough to simply check if a variable is present and if so, modify the query variables in the query hooks (such as pre_get_posts
) and load your own sub-post with the changelog template.
You may also want to experiment with different permalink endpoint masks, e.g. EP_PAGES
References:
- Codex > Rewrite API and Codex > Rewrite API > add_rewrite_endpoint()
- Rewrite enpoints API post by Jon cave
- Monkeyman Rewrite Analyzer plugin for rewrite debug
- Custom Post Type Permalinks post by ShibaShake (scroll down)