Invalid Menu Items

时间:2020-03-26 作者:knockknock

我注册了一个名为districts的分类法,但当我将districts添加到nav菜单时,nav菜单项无效!以下是注册分类的代码:


    function masallah() {

    // Add new taxonomy, make it hierarchical like categories
    //first do the translations part for GUI

        $labels = array(
            \'name\' => _x( \'Districts\', \'taxonomy general name\' ),
            \'singular_name\' => _x( \'District\', \'taxonomy singular name\' ),
            \'search_items\' =>  __( \'Search Districts\' ),
            \'all_items\' => __( \'All Districts\' ),
            \'parent_item\' => __( \'Parent Districts\' ),
            \'parent_item_colon\' => __( \'Parent District:\' ),
            \'edit_item\' => __( \'Edit District\' ),
            \'update_item\' => __( \'Update District\' ),
            \'add_new_item\' => __( \'Add New District\' ),
            \'new_item_name\' => __( \'New Topic District\' ),
            \'menu_name\' => __( \'Districts\' ),
        );

    // Now register the taxonomy

        register_taxonomy(\'Districts\',array(\'post\'), array(
            \'hierarchical\' => true,
            \'labels\' => $labels,
            \'show_ui\' => true,
            \'show_admin_column\' => true,
            \'query_var\' => true,
            \'show_in_rest\' => true,
            \'rewrite\' => true,
            \'rewrite\' => array( \'slug\' => \'districts\' ),
            \'has_archive\' => true,
        ));

    }

    add_action( \'init\', \'masallah\', 0 );

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

我已经确定了两个问题,第一个是:

            \'rewrite\' => true,
            \'rewrite\' => array( \'slug\' => \'districts\' ),
可能就是这样:

            \'rewrite\' => array( \'slug\' => \'districts\' ),
第二,你得到无效菜单项的原因是districts 正在用作重写slug,但分类法的内部名称为Districts.

更换Districts 具有districts 由于内部名称为我修复了本地问题:

register_taxonomy( \'districts\', array(\'post\'), array(
一般的经验法则是将事物的内部名称保持小写,您可以始终使用用户看到的标签

相关推荐

Making sub-menus exclusive

我真的不知道该怎么解释我在这里找的东西,我在这里找得太露骨了。在我的网站上,我有一个附带菜单,其中包含一系列子类别,每个子类别中都有一些项目。我想知道当我打开另一个子类别时,是否有办法关闭所有其他打开的子类别,例如:1. Animals ----A. Cats ----B. Dogs 2. People ----A. Samantha ----B. Daniel 当我按下“动物”时,我希望“人”关闭,反之亦