自定义分类法在自定义post-wordpress中不起作用


Custom taxonomy is not working in custom post wordpress

如何使用此代码添加分类法?当我点击新的分类法时,我会得到一个错误

    function people_init() {
    // create a new taxonomy
    register_taxonomy(
        'people',
        'new_post',
        array(
            'label' => __( 'People' ),
            'rewrite' => array( 'slug' => 'person' ),
            'capabilities' => array(
                'assign_terms' => 'edit_guides',
                'edit_terms' => 'publish_guides'
            )
        )
    );
}add_action( 'init', 'people_init' );

这是错误消息:

不允许您编辑此项目。

尝试以下代码:

function people_init() {
// create a new taxonomy
register_taxonomy(
    'people',
    'new_post',
    array(
        'label' => __( 'People' ),
        'rewrite' => array( 'slug' => 'person' ),
    )
);
}add_action( 'init', 'people_init' );

这是有问题的代码。删除它将允许您创建和编辑术语。

'capabilities' => array(
    'assign_terms' => 'edit_guides',
    'edit_terms' => 'publish_guides'
)

默认情况下,edit_guidespublish_guides功能不存在,需要为所选用户创建,然后再将其添加回。有关如何执行此操作的详细信息,请参阅add_cap()的Wordpress Codex。