最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

My custom post type not show category

programmeradmin1浏览0评论

i have a problem, my ctp work, but when add new project, on the menu of right not show category

this is my code:

//
//***********************************************************//
//****************portfolio progetti   **********************//
//***********************************************************//
//***********************************************************//

function custom_post_type_prog() {
 
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Progetti di Area', 'Post Type General Name', 'generatepress' ),
        'singular_name'       => _x( 'Progetto', 'Post Type Singular Name', 'generatepress' ),
        'menu_name'           => __( 'Progetti', 'generatepress' ),
        'parent_item_colon'   => __( 'Parent Progetto', 'generatepress' ),
        'all_items'           => __( 'Tutti i progetti', 'generatepress' ),
        'view_item'           => __( 'Vedi Progetto', 'generatepress' ),
        'add_new_item'        => __( 'Aggiungi nuovo progetto', 'generatepress' ),
        'add_new'             => __( 'Aggiungi progetto', 'generatepress' ),
        'edit_item'           => __( 'Edit Progetto', 'generatepress' ),
        'update_item'         => __( 'Update Progetto', 'generatepress' ),
        'search_items'        => __( 'Search Progetto', 'generatepress' ),
        
        'not_found'           => __( 'Not Found', 'generatepress' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'generatepress' ),
    );
     
// Set other options for Custom Post Type
     
    $args = array(
        'label'               => __( 'Progetti', 'generatepress' ),
        'description'         => __( 'Progetti di area-55', 'generatepress' ),
        'labels'              => $labels,
        'supports'            => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky'),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'menu_icon'           => 'dashicons-hammer',
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
        'show_in_rest'        => true,
        // This is where we add taxonomies to our CPT
        'taxonomies'          => array( 'progetti_cat','post_tag' ),
    );
     
    // Registering your Custom Post Type
    register_post_type( 'progetti', $args );
 
}

 add_action( 'init', 'custom_post_type_prog', 0 );


add_action( 'init', 'custom_taxonomy' );

// Register Custom Taxonomy
function custom_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Categorie progetti', 'Taxonomy General Name', 'generatepress' ),
        'singular_name'              => _x( 'Categoria Progetto', 'Taxonomy Singular Name', 'generatepress' ),
        'menu_name'                  => __( 'Categoria Progetti', 'generatepress' ),
        'all_items'                  => __( 'All Items', 'generatepress' ),
        'parent_item'                => __( 'Parent Item', 'generatepress' ),
        'parent_item_colon'          => __( 'Parent Item:', 'generatepress' ),
        'new_item_name'              => __( 'New Item Name', 'generatepress' ),
        'add_new_item'               => __( 'Add New Item', 'generatepress' ),
        'edit_item'                  => __( 'Edit Item', 'generatepress' ),
        'update_item'                => __( 'Update Item', 'generatepress' ),
        'view_item'                  => __( 'View Item', 'generatepress' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'generatepress' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'generatepress' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'generatepress' ),
        'popular_items'              => __( 'Popular Items', 'generatepress' ),
        'search_items'               => __( 'Search Items', 'generatepress' ),
        'not_found'                  => __( 'Not Found', 'generatepress' ),
        'no_terms'                   => __( 'No items', 'generatepress' ),
        'items_list'                 => __( 'Items list', 'generatepress' ),
        'items_list_navigation'      => __( 'Items list navigation', 'generatepress' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'progetti_cat', array( 'progetti' ), $args );

}

i have a problem, my ctp work, but when add new project, on the menu of right not show category

this is my code:

//
//***********************************************************//
//****************portfolio progetti   **********************//
//***********************************************************//
//***********************************************************//

function custom_post_type_prog() {
 
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Progetti di Area', 'Post Type General Name', 'generatepress' ),
        'singular_name'       => _x( 'Progetto', 'Post Type Singular Name', 'generatepress' ),
        'menu_name'           => __( 'Progetti', 'generatepress' ),
        'parent_item_colon'   => __( 'Parent Progetto', 'generatepress' ),
        'all_items'           => __( 'Tutti i progetti', 'generatepress' ),
        'view_item'           => __( 'Vedi Progetto', 'generatepress' ),
        'add_new_item'        => __( 'Aggiungi nuovo progetto', 'generatepress' ),
        'add_new'             => __( 'Aggiungi progetto', 'generatepress' ),
        'edit_item'           => __( 'Edit Progetto', 'generatepress' ),
        'update_item'         => __( 'Update Progetto', 'generatepress' ),
        'search_items'        => __( 'Search Progetto', 'generatepress' ),
        
        'not_found'           => __( 'Not Found', 'generatepress' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'generatepress' ),
    );
     
// Set other options for Custom Post Type
     
    $args = array(
        'label'               => __( 'Progetti', 'generatepress' ),
        'description'         => __( 'Progetti di area-55', 'generatepress' ),
        'labels'              => $labels,
        'supports'            => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky'),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'menu_icon'           => 'dashicons-hammer',
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
        'show_in_rest'        => true,
        // This is where we add taxonomies to our CPT
        'taxonomies'          => array( 'progetti_cat','post_tag' ),
    );
     
    // Registering your Custom Post Type
    register_post_type( 'progetti', $args );
 
}

 add_action( 'init', 'custom_post_type_prog', 0 );


add_action( 'init', 'custom_taxonomy' );

// Register Custom Taxonomy
function custom_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Categorie progetti', 'Taxonomy General Name', 'generatepress' ),
        'singular_name'              => _x( 'Categoria Progetto', 'Taxonomy Singular Name', 'generatepress' ),
        'menu_name'                  => __( 'Categoria Progetti', 'generatepress' ),
        'all_items'                  => __( 'All Items', 'generatepress' ),
        'parent_item'                => __( 'Parent Item', 'generatepress' ),
        'parent_item_colon'          => __( 'Parent Item:', 'generatepress' ),
        'new_item_name'              => __( 'New Item Name', 'generatepress' ),
        'add_new_item'               => __( 'Add New Item', 'generatepress' ),
        'edit_item'                  => __( 'Edit Item', 'generatepress' ),
        'update_item'                => __( 'Update Item', 'generatepress' ),
        'view_item'                  => __( 'View Item', 'generatepress' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'generatepress' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'generatepress' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'generatepress' ),
        'popular_items'              => __( 'Popular Items', 'generatepress' ),
        'search_items'               => __( 'Search Items', 'generatepress' ),
        'not_found'                  => __( 'Not Found', 'generatepress' ),
        'no_terms'                   => __( 'No items', 'generatepress' ),
        'items_list'                 => __( 'Items list', 'generatepress' ),
        'items_list_navigation'      => __( 'Items list navigation', 'generatepress' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'progetti_cat', array( 'progetti' ), $args );

}
Share Improve this question edited Feb 16, 2021 at 4:08 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Feb 15, 2021 at 22:11 ExolonExolon 54 bronze badges 2
  • what menu on the right? how is that menu created? – Michael Commented Feb 15, 2021 at 22:47
  • tinyurl/y2tunexz – Exolon Commented Feb 15, 2021 at 22:57
Add a comment  | 

1 Answer 1

Reset to default 0

the $args need to onclude 'show_in_rest' => true

from https://developer.wordpress/reference/functions/register_taxonomy/

'show_in_rest' (bool) Whether to include the taxonomy in the REST API. Set this to true for the taxonomy to be available in the block editor. Blockquote

发布评论

评论列表(0)

  1. 暂无评论