For a specific post, I want to create the illusion of child-posts.
The current post permalink structure is set to /%year%/%postname%/
. So using this post URL as an example:
/2020/post-slug/
I would also like the following URLs to render the same Post:
/2020/post-slug/hello/
/2020/post-slug/small-world/
My hope was that something like this would suffice (in functions.php), where the Post ID
is 1000
:
function custom_rewrite_rule() {
add_rewrite_rule('^2020/post-slug/([^/]*)/?','index.php?p=1000&path=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
The idea is that I would also pass the additional path information to the post which would be picked up in the template for some changes to original post.
When I do this, it loads the intended post but the URL changes back to:
/2020/post-slug/
...and I wanted the longer one to remain.
(I hard-flush rewrite rules in-between attempts).