You can add a rewrite tag and rules that capture anything after the post name:
function wpd_add_rewrites(){
add_rewrite_tag( '%my_page%', '(.+)' );
$post_types = array(
'movie',
'book',
'album'
);
foreach( $post_types as $post_type ){
add_rewrite_rule(
'^' . $post_type . '/([^/]*)/([^/]*)/?',
'index.php?post_type=" . $post_type . "&name=$matches[1]&my_page=$matches[2]',
'top'
);
}
}
add_action( 'init', 'wpd_add_rewrites' );
Don’t forget, you must flush rewrite rules after adding / changing them. You can do this quickly by just visiting the Settings > Permalinks page.
You can then check the value of my_page
anywhere after the wp
action:
echo get_query_var( 'my_page' );