【问题标题】:Custom taxonomy is not working in custom post wordpress自定义分类在自定义帖子 wordpress 中不起作用
【发布时间】:2013-12-10 12:35:14
【问题描述】:

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

    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' );

这是错误信息:

您无权编辑此项目。

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    试试下面的代码:

    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' => 数组('assign_terms' => 'edit_guides', 'edit_terms' => 'publish_guides' )
    • 因为你传递了错误的参数,你可以使用 like 'capabilities' => array( 'assign_terms' => 'edit_posts', 'edit_terms' => 'manage_categories' )
    • 工作正常 :) 非常感谢。但我对这些功能感到困惑?它们是什么,做什么? ..再次感谢
    • 用于将能力分配给分类的功能,但它是可选的。您也可以创建自己的功能。 PL。如果工作正常,请接受答案。
    【解决方案2】:

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

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

    edit_guidespublish_guides 功能默认不存在,需要在重新添加之前为您选择的用户创建。有关如何执行此操作的详细信息,请参阅add_cap() 的 Wordpress Codex。

    【讨论】:

    • 好的,谢谢..但是功能和参数的作用是什么
    • 能力设置谁可以做什么。 Wordpress 有五个默认的Roles,它们都默认设置了功能。在这种情况下分配可选的自定义功能将允许您设置 WP,以便只有特定用户(无论他们拥有什么 Role)可以为自定义分类创建/编辑术语。如果您不定义功能,WP 只会使用默认功能,因此任何拥有Role“编辑器”(或更高版本)的人都可以创建/编辑术语。查看 Roles and Capabilities 的 Codex 以获取更多信息。
    猜你喜欢
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多