自定义wordpress分类功能不适用于自定义帖子类型

自定义wordpress分类功能不适用于自定义帖子类型,wordpress,custom-post-type,custom-taxonomy,Wordpress,Custom Post Type,Custom Taxonomy,我的2个自定义wordpress分类法有问题 我已经创建了一个名为“kurs”的自定义帖子类型,对于这个自定义帖子类型,我还创建了两个自定义层次分类法。在我想为这2个分类添加自定义功能之前,这一切都很好 我已经为这两个功能添加了“功能”参数 第一分类法: 'capabilities' => array( 'manage_terms' => 'manage_location', 'edit_terms' => 'edit_location'

我的2个自定义wordpress分类法有问题

我已经创建了一个名为“kurs”的自定义帖子类型,对于这个自定义帖子类型,我还创建了两个自定义层次分类法。在我想为这2个分类添加自定义功能之前,这一切都很好

我已经为这两个功能添加了“功能”参数

第一分类法:

    'capabilities' => array(
        'manage_terms' => 'manage_location',
        'edit_terms' => 'edit_location',
        'delete_terms' => 'delete_location',
        'assign_terms' => 'assign_location',
    )
    'capabilities' => array(
        'manage_terms' => 'manage_typ',
        'edit_terms' => 'edit_typ',
        'delete_terms' => 'delete_typ',
        'assign_terms' => 'assign_typ',
    )
第二分类法:

    'capabilities' => array(
        'manage_terms' => 'manage_location',
        'edit_terms' => 'edit_location',
        'delete_terms' => 'delete_location',
        'assign_terms' => 'assign_location',
    )
    'capabilities' => array(
        'manage_terms' => 'manage_typ',
        'edit_terms' => 'edit_typ',
        'delete_terms' => 'delete_typ',
        'assign_terms' => 'assign_typ',
    )
然后,我使用此功能向管理员角色添加了所有这些新的自定义功能:

    function kurse_role_caps() {
    // gets the simple_role role object
    $role = get_role('administrator');

    // add a new capability
    $role->add_cap( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ', true);
    }

    add simple_role capabilities, priority must be after the initial role definition
    add_action('init', 'kurse_role_caps', 11);
但是第二个自定义分类法没有显示在管理菜单中,即使我将参数“show_in_menu”设置为true:

如果我从第二个分类中删除自定义功能,它将显示在管理中:


在我在互联网上搜索这个问题之后,没有人有类似的问题。以下是我用于自定义帖子类型和2个自定义分类法的完整代码的要点:

请注意,
add\u cap
只接受一个功能作为字符串,因此必须循环所有功能。像这样改变你的功能

function kurse_role_caps() {
    // gets the simple_role role object
    $role = get_role('administrator');

    // add a new capability
    $capabilities = array( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ' );
    foreach( $capabilities as $cap ) {
        $role->add_cap( $cap );
    }
}

// add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);