CPT 的自定义分类法未在管理员中显示标签

Custom Taxonomy for CPT not showing tags in admin

我创建了一个名为 'event' 的自定义 post 类型,我正在为此 post 类型添加一个自定义分类法。我在自定义分类法中创建了 3 个标签,但是当我编辑一个新事件时 post,分类法没有返回并且显示“找不到标签”。

下面是 cpt 和分类法的代码。我是不是漏了什么。

-- 创建自定义 post 类型

   function bps_event_posttype() {
$labels = array(
    'name'               => _x( 'Events', 'post type general name' ),
    'singular_name'      => _x( 'Event', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'Event' ),
    'add_new_item'       => __( 'Event' ),
    'edit_item'          => __( 'Edit Event' ),
    'new_item'           => __( 'New Event' ),
    'all_items'          => __( 'All Events' ),
    'view_item'          => __( 'View Event' ),
    'search_items'       => __( 'Search Events' ),
    'not_found'          => __( 'No Events found' ),
    'not_found_in_trash' => __( 'No Events found in the Trash' ), 
    'parent_item_colon'  => '',
     'menu_name'          => 'Events');
$args = array(
    'labels'        => $labels,
    'description'   => 'custom event',
    'public'        => true,
    'exclude_from_search' => false,
    'query_var' => true,
    'show_in_menu' => true,
    'menu_position' => 4,
    'capability_type' => 'post',
    'rewrite' => array( 'slug' => 'events', 'with_front' => false ),
     'publicly_queryable' => true,
    'supports'      => array( 'title', 'editor', 'thumbnail', 
    'excerpt','page-attributes'),
    'taxonomies' => array('eventtype','location'),
    'hierarchical' => false,
    'has_archive' => true

    );
    register_post_type( 'event', $args );   
    }
    add_action( 'init', 'bps_event_posttype' );

-- 创建分类法并将其分配给事件 cpt

    function add_event_type_taxonomy() {

    register_taxonomy('eventtype', array('event'), array(


'public' => false,
'show_admin_column' => true,
 'show_ui' => true, 
  'query_var' => true,

'labels' => array(
  'name' => _x( 'Event Types', 'taxonomy general name' ),
  'singular_name' => _x( 'Event Type', 'taxonomy singular name' ),
  'search_items' =>  __( 'Search Event Types' ),
  'all_items' => __( 'All Event Types' ),
  'parent_item' => __( 'Parent Event Type' ),
  'parent_item_colon' => __( 'Parent Event Type:' ),
  'edit_item' => __( 'Edit Event Type' ),
  'update_item' => __( 'Update Event Type' ),
  'add_new_item' => __( 'Add New Event Type' ),
  'new_item_name' => __( 'New Event Type Name' ),
  'menu_name' => __( 'Event Types' ),
),

'rewrite' => array(
  'slug' => 'types', 
  'with_front' => false, 
  'hierarchical' => false 
   ),
    ));
    }
    add_action( 'init', 'add_event_type_taxonomy', 0 );

    register_taxonomy_for_object_type('eventtype', 'event');

编辑事件时post,如果我select“从最常用的标签中选择”,它会显示“未找到标签”。但分类编辑屏幕中有 3 个标签。

我已将您的代码添加到我的本地主机中,并检查了您的编码部分是否一切正常,没有任何问题,但是您错过了,您需要 select 标签至少一个事件以在“从最常用的标签中选择”区域中查看它。这是第一次它不会在那里显示任何标签。请看截图 https://prnt.sc/UujJXicZ729G 。它完美地显示了标签。希望您 select 在 select 标记一次后能够从所选区域标记。