Support Forum
Hi there -
I created a CPT and added it to my theme functions file. It was working well but the CPT would not show on the front end. I took a tip from another forum post to change permalinks to plain and that fixed it.
I switched the permalinks back to Post Name and it still works on the front end, but now I can't edit or create new posts for the CPT on the back end. Editing existing posts or trying to add new results in completely white screen.
I can create a new CPT and it works fine.
Here's my code:
<?php
add_action( 'init', 'your_prefix_register_post_type' );
function your_prefix_register_post_type() {
$labels = [
'name' => esc_html__( 'Coaching', 'your-textdomain' ),
'singular_name' => esc_html__( 'Coaching', 'your-textdomain' ),
'add_new' => esc_html__( 'Add New', 'your-textdomain' ),
'add_new_item' => esc_html__( 'Add new coaching', 'your-textdomain' ),
'edit_item' => esc_html__( 'Edit Coaching', 'your-textdomain' ),
'new_item' => esc_html__( 'New Coaching', 'your-textdomain' ),
'view_item' => esc_html__( 'View Coaching', 'your-textdomain' ),
'view_items' => esc_html__( 'View Coaching', 'your-textdomain' ),
'search_items' => esc_html__( 'Search Coaching', 'your-textdomain' ),
'not_found' => esc_html__( 'No coaching found', 'your-textdomain' ),
'not_found_in_trash' => esc_html__( 'No coaching found in Trash', 'your-textdomain' ),
'parent_item_colon' => esc_html__( 'Parent Coaching:', 'your-textdomain' ),
'all_items' => esc_html__( 'All Coaching', 'your-textdomain' ),
'archives' => esc_html__( 'Coaching Archives', 'your-textdomain' ),
'attributes' => esc_html__( 'Coaching Attributes', 'your-textdomain' ),
'insert_into_item' => esc_html__( 'Insert into coaching', 'your-textdomain' ),
'uploaded_to_this_item' => esc_html__( 'Uploaded to this coaching', 'your-textdomain' ),
'featured_image' => esc_html__( 'Featured image', 'your-textdomain' ),
'set_featured_image' => esc_html__( 'Set featured image', 'your-textdomain' ),
'remove_featured_image' => esc_html__( 'Remove featured image', 'your-textdomain' ),
'use_featured_image' => esc_html__( 'Use as featured image', 'your-textdomain' ),
'menu_name' => esc_html__( 'Coaching', 'your-textdomain' ),
'filter_items_list' => esc_html__( 'Filter coaching list', 'your-textdomain' ),
'items_list_navigation' => esc_html__( 'Coaching list navigation', 'your-textdomain' ),
'items_list' => esc_html__( 'Coaching list', 'your-textdomain' ),
'item_published' => esc_html__( 'Coaching published', 'your-textdomain' ),
'item_published_privately' => esc_html__( 'Coaching published privately', 'your-textdomain' ),
'item_reverted_to_draft' => esc_html__( 'Coaching reverted to draft', 'your-textdomain' ),
'item_scheduled' => esc_html__( 'Coaching scheduled', 'your-textdomain' ),
'item_updated' => esc_html__( 'Coaching updated', 'your-textdomain' ),
'text_domain' => esc_html__( 'your-textdomain', 'your-textdomain' ),
];
$args = [
'label' => esc_html__( 'Coaching', 'your-textdomain' ),
'labels' => $labels,
'description' => '',
'public' => true,
'hierarchical' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => true,
'query_var' => true,
'can_export' => true,
'delete_with_user' => true,
'has_archive' => false,
'rest_base' => '',
'show_in_menu' => true,
'menu_icon' => 'dashicons-star-empty',
'menu_position' => 28,
'capability_type' => 'post',
'supports' => ['title', 'editor', 'thumbnail'],
'taxonomies' => [],
'rewrite' => [
'with_front' => false,
],
];
register_post_type( 'coaching', $args );
}
From the error console when I try to add new:
Uncaught (in promise) Error: The entity being edited (postType, undefined) does not have a loaded config.
at core-data.min.js?ver=cae70cc4927f8b371fa13262d47b23e0:2
at tryCatch (wp-polyfill.min.js?ver=7.4.4:1)
at Generator.invoke [as _invoke] (wp-polyfill.min.js?ver=7.4.4:1)
at Generator.t.<computed> [as next] (wp-polyfill.min.js?ver=7.4.4:1)
at redux-routine.min.js?ver=284288e957394d2097c6fbe95625e2fb:2
at redux-routine.min.js?ver=284288e957394d2097c6fbe95625e2fb:2
at redux-routine.min.js?ver=284288e957394d2097c6fbe95625e2fb:2
at Array.some (<anonymous>)
at e (redux-routine.min.js?ver=284288e957394d2097c6fbe95625e2fb:2)
at redux-routine.min.js?ver=284288e957394d2097c6fbe95625e2fb:2
post-new.php?post_type=coaching:1 Unchecked runtime.lastError: The message port closed before a response was received.