plugin development – Custom Endpoint For Specific Custom Post Type

I register a new post type

register_post_type('movie', array(
    'labels'            =>  array(
        'name'               => __('Movies'),
        'singular_name'      => __('Movie'),
        'all_items'          => __('View Movies'),
        'add_new'            => __('New Movie'),
        'add_new_item'       => __('New Movie'),
        'edit_item'          => __('Edit Movie'),
        'view_item'          => __('View Movie'),
        'search_items'       => __('Search Movie'),
        'no_found'           => __('No Movie Found'),
        'not_found_in_trash' => __('No Movie in Trash')
    ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'query_var'          => true,
    'show_in_nav_menus'  => false,
    'capability_type'    => 'page',
    'hierarchical'       => true,
    'rewrite'            => ('slug' => 'movie'),
    'supports'           => array('title', 'editor', 'thumbnail'),
    'has_archive'        => true
));

and my URL permalink set Post name. my movies are show on font page with (mydomain)/movie/%postname%. Now I want to do some sub-section in my movie post type only.

  • (mydomain)/movie/%postname%/artists/
  • (mydomain)/movie/%postname%/songs/
  • (mydomain)/movie/%postname%/news/
  • (mydomain)/movie/%postname%/videos/
  • etc

and it also should support the .../page/2/ E.g

  • (mydomain)/movie/%postname%/news/page/2/
  • etc

I try do do with

add_action('init', 'my_custom_post_endpoint');
function my_custom_post_endpoint()
{
    add_rewrite_endpoint('news', EP_PAGES);
    add_rewrite_endpoint('videos', EP_PAGES);

    add_rewrite_endpoint('news', EP_PERMALINK);
    add_rewrite_endpoint('videos', EP_PERMALINK);
}

But with this it work but (mydomain)/movie/%postname%/news/page/2/ not working. I mean .../page/2 not working.

Questions:

  • How I can add endpoints for my movie post type only?
  • How add support .../page/2 after endpoint?
  • List item