I noticed that your post type is hierarchical, so you could actually add page-attributes
to the supports
array in your post type args, i.e. 'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
, then you could create those sub-sections as child of your movie
posts. But yes, the child posts will need to use unique slugs like news
, news2
, news-3
, etc.
So if that’s not preferred, then you may proceed to using the endpoint method.
But add_rewrite_endpoint()
doesn’t add the rewrite rules for pagination (the /page/<number>
one and with the EP_PAGES
place), so you might instead want to use add_rewrite_rule()
and have better control over the rewrite rules.
Here’s an example, and you can test the RegEx (regular expression) pattern here:
function my_custom_post_endpoint()
{
add_rewrite_rule(
'^movie/(.+?)/(news|videos)(?:/page/(\d+)|)/?$',
'index.php?movie=$matches[1]&paged=$matches[2]',
'top'
);
}
Don’t forget to flush the rewrite rules after applying the above code. Just visit the permalink settings admin page without having to click on the Save Changes button.