So, I have created a custom post type with custom taxonomy. Everything looks good and works, EXCEPT when I am creating a post and add a new category nothing happens. If I update the post then the category will show up. My code is below:
add_action( 'init', 'cut_files_custom_post_type' );
function cut_files_custom_post_type() {
$cut_file_labels = array(
'name' => _x( 'Cut Files', 'post type general name' ),
'singular_name' => _x( 'Cut File', 'post type singular name' ),
'add_new' => _x( 'Add Cut File', 'table' ),
'add_new_item' => __( 'Add New Cut File' ),
'edit_item' => __( 'Edit Cut File' ),
'new_item' => __( 'New Cut File' ),
'all_items' => __( 'All Cut Files' ),
'view_item' => __( 'View Cut File' ),
'search_items' => __( 'Search Cut Files' ),
'not_found' => __( 'No Cut Files found' ),
'not_found_in_trash' => __( 'No Cut Files found in the Trash' ),
'menu_name' => 'Cut Files'
);
$args= array(
'public' => true,
'labels' => $cut_file_labels,
'menu_icon' => 'dashicons-images-alt2',
'menu_position' => 20,
'taxonomies' => array( 'cut_file_category', 'cut_file_tag' ),
'has_archive' => true,
'show_in_rest' => false,
'hierarchical' => true,
'supports' => array( 'title', 'revisions' )
);
register_post_type( 'cut_files', $args);
}
add_action( 'init', 'aic_custom_taxonomies', 0 );
function aic_custom_taxonomies(){
// Cut File Categories
$cut_file_tax_labels = array(
'name' => _x( 'Cut File Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Cut File Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Cut File Categories' ),
'all_items' => __( 'All Cut File Categories' ),
'parent_item' => __( 'Parent Cut File Category' ),
'parent_item_colon' => __( 'Parent Cut File Category:' ),
'edit_item' => __( 'Edit Cut File Category' ),
'update_item' => __( 'Update Cut File Category' ),
'add_new_item' => __( 'Add New Cut File Category' ),
'new_item_name' => __( 'New Cut File Category' ),
'menu_name' => __( 'Cut File Categories' )
);
$args = array(
'labels' => $cut_file_tax_labels,
'hierarchical' => true,
'query_var' => true,
'rewrite' => true,
'show_in_rest' => true
);
register_taxonomy( 'cut_file_category', 'cut_file_items', $args );
// Cut File Tags
$cut_file_tax_labels = array(
'name' => _x( 'Cut File Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Cut File Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Cut File Tags' ),
'all_items' => __( 'All Cut File Tags' ),
'parent_item' => __( 'Parent Cut File Tag' ),
'parent_item_colon' => __( 'Parent Cut File Tag:' ),
'edit_item' => __( 'Edit Cut File Tag' ),
'update_item' => __( 'Update Cut File Tag' ),
'add_new_item' => __( 'Add New Cut File Tag' ),
'new_item_name' => __( 'New Cut File Tag' ),
'menu_name' => __( 'Cut File Tags' )
);
$args = array(
'labels' => $cut_file_tax_labels,
'hierarchical' => false,
'show_in_rest' => true
);
register_taxonomy( 'cut_file_tag', 'cut_file_items', $args );
}
When I look at the console for errors, I get this:
Uncaught TypeError: Cannot read properties of undefined (reading 'responses')
at Object.catAddAfter [as addAfter] (post.js?ver=5.8.1:647)
at Object.settings.complete (wp-lists.js?ver=5.8.1:385)
at fire (jquery.js?ver=3.6.0:3500)
at Object.fireWith (jquery.js?ver=3.6.0:3630)
at done (jquery.js?ver=3.6.0:9811)
at XMLHttpRequest.<anonymous> (jquery.js?ver=3.6.0:10057)
It is in the post.js file in wp-admin.
Any help on where I'm going wrong would be greatly appreciated.
source https://stackoverflow.com/questions/69728723/add-category-button-not-working-correctly
Comments
Post a Comment