【问题标题】:WordPress - Custom taxonomies not showing in Appearance > MenuWordPress - 自定义分类法未显示在外观 > 菜单中
【发布时间】:2019-10-07 10:16:04
【问题描述】:

我有一个名为 Resources 的自定义帖子类型:

register_post_type(
    'resources',
    build_post_args(
        'resources', 'Resource', 'Resources',
        array(
            'menu_icon'     => 'dashicons-welcome-write-blog',
            'menu_position' => 20,
            'has_archive' => true,
            'public'      => true,
            'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
            'taxonomies' => array('sector', 'subject', 'type'),
        )
    )
);

我还创建了分配给资源的type 的分类:

register_taxonomy(  
    'type', 
    'type', 
    array(  
        'hierarchical' => true,  
        'label' => 'Type',  
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'type', 
            'with_front' => false 
        ) 
    )
); 

在 WordPress 后端,这里是我所有的type

但是,当我转到外观 > 菜单 > 并单击类别下拉菜单时,仅显示以下选项:

这是为什么?

【问题讨论】:

    标签: wordpress custom-post-type custom-taxonomy


    【解决方案1】:

    您好,请添加以下代码并检查,因为您在创建 resources 帖子类型时缺少很多东西。 (注意:请删除您为创建resources 帖子和type 分类添加的所有代码)

    function ro_resources_custom_post_type() {
        $labels = array(
            'name'                => __( 'Resources' ),
            'singular_name'       => __( 'Resource'),
            'menu_name'           => __( 'Resources'),
            'parent_item_colon'   => __( 'Parent Resource'),
            'all_items'           => __( 'All Resources'),
            'view_item'           => __( 'View Resource'),
            'add_new_item'        => __( 'Add New Resource'),
            'add_new'             => __( 'Add New'),
            'edit_item'           => __( 'Edit Resource'),
            'update_item'         => __( 'Update Resource'),
            'search_items'        => __( 'Search Resource'),
            'not_found'           => __( 'Not Found'),
            'not_found_in_trash'  => __( 'Not found in Trash')
        );
        $args = array(
            'label'               => __( 'resources'),
            'description'         => __( 'Best Resources'),
            'labels'              => $labels,
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
            'public'              => true,
            'hierarchical'        => false,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
            'has_archive'         => true,
            'can_export'          => true,
            'exclude_from_search' => false,
                'yarpp_support'       => true,
            'publicly_queryable'  => true,
            'capability_type'     => 'page'
    );
        register_post_type( 'resources', $args );
    }
    add_action( 'init', 'ro_resources_custom_post_type', 0 );
    
    add_action( 'init', 'ro_create_resources_custom_taxonomy', 0 );
    
    //create a custom taxonomy name it "type" for your posts
    function ro_create_resources_custom_taxonomy() {
    
      $labels = array(
        'name' => _x( 'Types', 'taxonomy general name' ),
        'singular_name' => _x( 'Type', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Types' ),
        'all_items' => __( 'All Types' ),
        'parent_item' => __( 'Parent Type' ),
        'parent_item_colon' => __( 'Parent Type:' ),
        'edit_item' => __( 'Edit Type' ), 
        'update_item' => __( 'Update Type' ),
        'add_new_item' => __( 'Add New Type' ),
        'new_item_name' => __( 'New Type Name' ),
        'menu_name' => __( 'Types' ),
      );    
    
      register_taxonomy('types',array('resources'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'type' ),
      ));
    }
    

    经过测试并运行良好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 2016-01-04
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多