在 wordpress 中限制自定义 post 类型的类别

Restrict category for custom post type in wordpress

我创建了一个用于添加员工的自定义 post 类型。我已经为它添加了类别分类法。然后我添加了一个名为 "Employees" 的类别(slug:employees)。但是当我添加一名新员工时,它会显示所有可供选择的类别。我怎样才能限制它只显示 "Employees" 类别?

这是我在 functions.php 中的 php 代码:

function employees_register() {
    $labels = array(
        'name' => _x('Employees', 'post type general name'),
        'singular_name' => _x('Employee', 'post type singular name'),
        'add_new' => _x('Add New', 'employees'),
        'add_new_item' => __('Add New Employee'),
        'edit_item' => __('Edit Employee'),
        'new_item' => __('New Employee'),
        'view_item' => __('View Employee'),
        'search_items' => __('Search Employee'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'taxonomies' => array( 'category' ),
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail')
      ); 

    register_post_type( 'employees' , $args );
}
add_action('init', 'employees_register');

您应该使用 register_taxonomy() 函数注册自定义分类法:

add_action( 'init', 'employee_tax' );

function create_book_tax() {
    register_taxonomy(
        'employee-categories',
        'employees',
        array(
            'label' => __( 'Employee Categories' ),
            'hierarchical' => true,
        )
    );
}

https://codex.wordpress.org/Function_Reference/register_taxonomy

然后,只有这些分类法会显示为 post 类型的选项,而不是其他 post 类型的类别。