0

I have created a new custom post type in wordpress using register_post_type() function But when I click on add new in right side the editor not showing template choose option as you can see in Screenshot_01.png. In Screenshot_2 you can see the default add post option has the template choose option. How can I get that option without using plugin. Here is my exiting code for creating custom post type.

function short_story_type(){
    $labels = array(
        'name' => _x( 'storys', 'Post Type General Name', 'textdomain' ),
        'singular_name' => _x( 'story', 'Post Type Singular Name', 'textdomain' ),
        'menu_name' => _x( 'storys', 'Admin Menu text', 'textdomain' ),
        'name_admin_bar' => _x( 'story', 'Add New on Toolbar', 'textdomain' ),
        'archives' => __( 'story Archives', 'textdomain' ),
        'attributes' => __( 'story Attributes', 'textdomain' ),
        'parent_item_colon' => __( 'Parent story:', 'textdomain' ),
        'all_items' => __( 'All storys', 'textdomain' ),
        'add_new_item' => __( 'Add New story', 'textdomain' ),
        'add_new' => __( 'Add New', 'textdomain' ),
        'new_item' => __( 'New story', 'textdomain' ),
        'edit_item' => __( 'Edit story', 'textdomain' ),
        'update_item' => __( 'Update story', 'textdomain' ),
        'view_item' => __( 'View story', 'textdomain' ),
        'view_items' => __( 'View storys', 'textdomain' ),
        'search_items' => __( 'Search story', 'textdomain' ),
        'not_found' => __( 'Not found', 'textdomain' ),
        'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),
        'featured_image' => __( 'Featured Image', 'textdomain' ),
        'set_featured_image' => __( 'Set featured image', 'textdomain' ),
        'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),
        'use_featured_image' => __( 'Use as featured image', 'textdomain' ),
        'insert_into_item' => __( 'Insert into story', 'textdomain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this story', 'textdomain' ),
        'items_list' => __( 'storys list', 'textdomain' ),
        'items_list_navigation' => __( 'storys list navigation', 'textdomain' ),
        'filter_items_list' => __( 'Filter storys list', 'textdomain' ),
    );
    $args = array(
        'label' => __( 'story', 'textdomain' ),
        'description' => __( '', 'textdomain' ),
        'labels' => $labels,
        'menu_icon' => 'dashicons-album',
        'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'author', 'comments', 'trackbacks', 'page-attributes', 'post-formats', 'custom-fields'),
        'taxonomies' => array(),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'can_export' => true,
        'has_archive' => true,
        'hierarchical' => false,
        'exclude_from_search' => true,
        'show_in_rest' => true,
        'publicly_queryable' => true,
        'capability_type' => 'post',
    );
    register_post_type( 'story', $args );




}
add_action('init', 'short_story_type'); 
1
  • there are no screenshots in your question, can you edit it to include them or remove the references?
    – Tom J Nowell
    Commented Oct 21, 2022 at 12:29

2 Answers 2

2

Not sure where these screenshots you're talking about have gone, no matter, i think i know the problem.

You simply need to add support for the post type in the templates you want to be able to attach by adjusting the Template Post Type: line for the appropriate template files in your theme.

Example

Template Post Type: post, books, movies

The dropdown should then appear in the editor like it does for posts.

0

Try to change

'`capability_type' => 'post',`

to

'capability_type' => 'page',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.