Closed ihdk closed 3 years ago
Hello, after further investigation I found that templates selection is missing in wp5.8 if my custom post type is registered with public
parameter set to false
.
Once the public
parameter is defined as true
I can select the template.
Is it really wanted behavior in WP 5.8 ?
To make sure it has nothing to do with my other custom codes, I've tested it with TwentytwentyOne theme, with following code in functions.php
add_action( 'init', 'register_cpt' );
function register_cpt() {
register_post_type( 'my-cpt', [
'labels' => [
'name' => esc_html_x( 'My CPTs', 'post type general name', 'textdomain' ),
'singular_name' => esc_html_x( 'My CPT', 'post type singular name', 'textdomain' ),
'menu_name' => esc_html_x( 'My CPTs', 'admin menu', 'textdomain' ),
'edit_item' => esc_html__( 'Edit My CPT', 'textdomain' ),
'all_items' => esc_html__( 'All My CPTs', 'textdomain' ),
'search_items' => esc_html__( 'Search Special ages', 'textdomain' ),
'not_found' => esc_html__( 'No My CPTs found.', 'textdomain' ),
'filter_items_list' => esc_html__( 'Filter My CPTs list', 'textdomain' ),
'items_list_navigation' => esc_html__( 'My CPTs list navigation', 'textdomain' ),
'items_list' => esc_html__( 'My CPTs list', 'textdomain' ),
'item_updated' => esc_html__( 'My CPT updated.', 'textdomain' ),
],
'public' => false,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => false,
'show_in_rest' => true,
'capabilities' => [
'read_private_posts' => 'read_private_my_cpts',
'read_post' => 'read_my_cpt',
'publish_posts' => 'publish_my_cpts',
'edit_post' => 'edit_my_cpt',
'edit_posts' => 'edit_my_cpts',
'create_posts' => 'create_my_cpts',
'delete_posts' => 'delete_my_cpts',
],
'supports' => [
'title',
'editor',
'custom-fields',
],
] );
$role = get_role( 'administrator' );
foreach ( [
'read_private_my_cpts',
'read_my_cpt',
'publish_my_cpts',
'edit_my_cpt',
'edit_my_cpts',
'create_my_cpts',
'delete_my_cpts'
] as $cap ) {
$role->add_cap( $cap );
}
}
add_filter( 'theme_my-cpt_templates', 'theme_my_cpt_templates' );
function theme_my_cpt_templates( $templates ){
$templates["page-templates/template-first.php"] = __( 'First template', 'textdomain');
$templates["page-templates/template-second.php"] = __( 'Second template', 'textdomain');
return $templates;
}
Thanks for your help.
Im missing the template selection even on normal pages ..
I only have a page.php and page-fullwidth.php (marked correctly with Template Name:
) in my themes, no custom post types or anything special.
Hello, @ihdk
We tested this issue during a triage session today.
While we were able to reproduce the issue, it looks like to be the expected behavior. If you can't publicly access the post type, there's no need for the front-end template. Setting public
to false
means that the post type isn't publicly accessible.
@Azragh Recently, "Templates" were moved into their panel and should be available at the very top of the sidebar.
Description
Hello, I'm using Custom Post Type with custom Templates. Available templates are available on this custom post edit page with WP 5.7.2. After update to WP 5.8-RC3 I can see that Templates selection was moved from Page Attributes tab to Template tab in editor screen while I am editing standard Page. But on my custom post type edit screen there is totally missing Template tab to select from available templates.
Custom Templates for my Custom Post Type are added using
theme_{$post_type}_templates
filter, exactly following instruction in https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/ what worked perfectly until update to WP 5.8Thanks for any response...
Step-by-step reproduction instructions
theme_{$post_type}_templates
filter with latest public WP versionExpected behaviour
After update to WP5.8 there would be Template selection on Custom Post Type edit page like it's still available on edit page of standard Page.