我在WP中创建了cpt并没有显示分类,我做错了什么?

I created cpt in WP and did not show the taxonomy, what did I do wrong?

我在下面创建了 Wordpress 插件,以在管理面板中显示名为文章的 CPT。

在此 CPT 中,我创建了一个分类项来注册类别。

但是我在创建显示 CPT 分类法的部分时遇到了问题。

显然代码部分是正确的,但我没有发现问题。

我需要帮助找出我在代码中写错了什么,以及为什么它没有在我创建的 CPT 菜单中显示分类项。

<?php
/*
Plugin Name: Artigos
Version: 1.0
*/

/*POST TYPE*/
add_action('init', 'cpt_artigos');
function cpt_artigos() { 

        $labels = array(
            'menu_name'          => __('Artigos'),
            'name'               => __('Artigos'),
            'singular_name'      => __('Artigo'),
            'all_items'          => __('Todos os cadastros'),
            'add_new'            => __('Adicionar novo cadastro', 'Novo cadastro'),
            'add_new_item'       => __('Novo cadastro'),
            'edit'               => __('Editar'),
            'edit_item'          => __('Editar cadastro'),
            'new_item'           => __('Novo cadastro'),
            'view'               => __('Ver'),
            'view_item'          => __('Ver cadastro'),
            'search_items'       => __('Procurar cadastros'),
            'not_found'          => __('Nenhum registro encontrado'),
            'not_found_in_trash' => __('Nenhum registro encontrado na lixeira'),      
         );

        $args = array(
            'labels' => $labels,            
            'menu_icon'           => 'dashicons-star-filled', 
            'capability_type'     => 'post', 
            'menu_position'       => 5, 
            'supports'            => array('title','editor','thumbnail'), 
            'public'              => true, 
            'publicly_queryable'  => true, 
            'exclude_from_search' => false, 
            'show_ui'             => true, 
            'show_in_nav_menus'   => true, 
            'show_in_menu'        => true, 
            'show_in_admin_bar'   => true, 
            'query_var'           => true, 
            'can_export'          => true, 
            'has_archive'         => true, 
            'hierarchical'        => true, 
            'rewrite'             => true 
         );

register_post_type( 'artigos' , $args ); 
flush_rewrite_rules();
}


//TAXONOMY
add_action( 'init', 'taxonomyartigos');
function taxonomyartigos() {

    $labels = array(
        'menu_name'         => __( 'Categorias de Artigos' ),
        'name'              => __( 'Categorias de Artigos' ),
        'singular_name'     => __( 'Categoria de Artigo' ),
        'search_items'      => __( 'Procurar Cadastros' ),
        'all_items'         => __( 'Todos os Cadastros' ),
        'parent_item'       => __( 'Categoria de Artigo Principal' ),
        'parent_item_colon' => __( 'Categoria de Artigo Principal:' ),
        'edit_item'         => __( 'Editar Cadastro' ), 
        'update_item'       => __( 'Atualizar Cadastro' ),
        'add_new_item'      => __( 'Adicionar novo cadastro' ),
        'new_item_name'     => __( 'Novo Cadastro' ),
     ); 

    $args = array(

        'labels'            => $labels,
        'public'            => true,
        'hierarchical'      => true,
        'show_ui'           => true,
        'show_admin_column' => true,
        'show_in_nav_menus' => true,
        'show_tagcloud'     => true,
        'show_in_nav_menus' => true,
        'has_archive'       => true,        
        'rewrite'           => true,
    );

register_taxonomy( 'taxonomyartigos', array( 'cpt_artigos' ), $args );
flush_rewrite_rules();
}


function cpt_artigos_flush_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}
add_action('init', 'cpt_artigos_flush_rewrite');
?>

您需要写 post 类型名称而不是函数

register_taxonomy( 'taxonomyartigos', 'artigos', $args );

希望可以。