May 08, 2019
Add show_in_rest => true to the array for the custom post type to enable the gutenberg editor, and to the taxonomy to have the item appear in the Gutenberg editor’s sidebar.
Custom Post Type
add_action( 'init', 'create_post_type' ); function create_post_type() { $labels = array( 'name' => _x('Blocks', 'post type general name'), 'singular_name' => _x('Block', 'post type singular name'), 'add_new' => _x('Add New Block', 'Block'), 'add_new_item' => __('Add New Block'), 'edit_item' => __('Edit Block'), 'new_item' => __('New Block'), 'all_items' => __('All Blocks'), 'view_item' => __('View Block'), 'search_items' => __('Search Blocks'), 'not_found' => __('No Blocks found'), 'not_found_in_trash' => __('No Blocks found in Trash'), 'parent_item_colon' => '', 'menu_name' => __('Blocks') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'show_in_rest' => true, // where the magic happens, must be above supports to show the gutenberg editor 'supports' => array( 'title', 'revisions', 'thumbnail', 'editor' ), 'exclude_from_search' => true, 'taxonomy' => array('block_category'), ); register_post_type('custom-blocks',$args); }
Taxonomy
function register_taxonomies(){ register_taxonomy('block_category','post',array( 'label' => __( 'Category' ), 'rewrite' => array( 'slug' => 'block_category' ), 'hierarchical' => true, 'query_var' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_admin_column' => true, 'show_in_rest' => true // where the magic happens
)); } add_action('init','register_taxonomies');