Templates for hierarchical custom post type
I'm a bit confused with templates for custom post types defined as hierarchical. I've got a CPT set to hierarchical, not strictly in order to have a nested hierarchy, but so that they can be ordered by the Simple Page Ordering plugin. Here's the code:
register_post_type(
'case_study', array(
'label' = _x( 'case studies', 'post type plural name' ),
'labels' = array(
'name' = _x( 'Case studies', 'post type general name' ),
'singular_name' = _x( 'Case study', 'post type singular name' ),
'menu_name' = _x( 'Case studies', 'admin menu' ),
'name_admin_bar' = _x( 'Case study', 'add new on admin bar' ),
'add_new' = _x( 'Add New', 'case study' ),
'add_new_item' = __( 'Add New Case study' ),
'new_item' = __( 'New Case study' ),
'edit_item' = __( 'Edit Case study' ),
'view_item' = __( 'View Case study' ),
'all_items' = __( 'All Case studies' ),
'search_items' = __( 'Search Case studies' ),
'parent_item_colon' = __( 'Parent Case studies:' ),
'not_found' = __( 'No Case studies found.' ),
'not_found_in_trash' = __( 'No Case studies found in Trash.' )
),
'public' = true,
'publicly_queryable' = true,
'show_ui' = true,
'show_in_nav_menus' = true,
'show_in_menu' = true,
'show_in_admin_bar' = true,
'menu_position' = 20, // Below Pages
'menu_icon' = 'dashicons-clipboard', // @link https://developer.wordpress.org/resource/dashicons/
'query_var' = false,
'rewrite' = array( 'slug' = 'case-study', 'with_front' = false ),
'capability_type' = 'case_study',
'map_meta_cap' = false,
'capabilities' = array(
'publish_posts' = 'publish_case_studies',
'edit_posts' = 'edit_case_studies',
'edit_others_posts' = 'edit_others_case_studies',
'delete_posts' = 'delete_case_studies',
'delete_others_posts' = 'delete_others_case_studies',
'read_private_posts' = 'read_private_case_studies',
'edit_post' = 'edit_case_study',
'delete_post' = 'delete_case_study',
'read_post' = 'read_case_study',
),
'has_archive' = false,
'hierarchical' = true, // Set to true to allow ordering
'supports' = array( 'title', 'editor', 'custom-fields', 'thumbnail', 'revisions', 'pilau-author' ),
'taxonomies' = array( 'topic' ),
)
);
By default a hierarchical CPT uses the page.php template instead of single.php - which took me a while to realise, but it makes sense.
However, now I want to create a template specifically for this CPT, and single-case_study.php doesn't work. Neither does page-case_study.php.
How do you create a template specifically for a hierarchical CPT?
Topic template-hierarchy hierarchical templates custom-post-types Wordpress
Category Web