我的自定义帖子类型不显示类别

时间:2021-02-15 作者:Exolon

我有一个问题,我的ctp工作,但当添加新项目时,在右菜单上不显示类别

这是我的代码:

//
//***********************************************************//
//****************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 );

}

1 个回复
最合适的回答,由SO网友:Michael 整理而成

这个$args 需要排除\'show_in_rest\' => true

从…起https://developer.wordpress.org/reference/functions/register_taxonomy/

“show\\u in\\u rest”(bool)是否在rest API中包含分类法。将此设置为true,以使分类法在块编辑器中可用。区块报价单

相关推荐