自定义分类未显示在管理菜单中

时间:2017-04-07 作者:Jon

我在functions.php 使用以下代码:

<?php
add_action( \'init\', function() {
    $labels = array(
        \'name\'              => _x( \'Resource Centers\', \'taxonomy general name\', \'textdomain\' ),
        \'singular_name\'     => _x( \'Resource Center\', \'taxonomy singular name\', \'textdomain\' ),
        \'search_items\'      => __( \'Search Resource Centers\', \'textdomain\' ),
        \'all_items\'         => __( \'All Resource Centers\', \'textdomain\' ),
        \'parent_item\'       => __( \'Parent Resource Center\', \'textdomain\' ),
        \'parent_item_colon\' => __( \'Parent Resource Center:\', \'textdomain\' ),
        \'edit_item\'         => __( \'Edit Resource Center\', \'textdomain\' ),
        \'update_item\'       => __( \'Update Resource Center\', \'textdomain\' ),
        \'add_new_item\'      => __( \'Add New Resource Center\', \'textdomain\' ),
        \'new_item_name\'     => __( \'New Resource Center Name\', \'textdomain\' ),
        \'menu_name\'         => __( \'Resource Center\', \'textdomain\' ),
    );
    $args = array(
        \'hierarchical\'      => true,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        \'show_in_menu\'      => true,
        \'public\'            => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => array( \'slug\' => \'resource-center\' ),
    );
    register_taxonomy( \'resource-center\', array( \'post\' ), $args );
    $labels = array(
        \'name\'              => _x( \'Blog Categories\', \'taxonomy general name\', \'textdomain\' ),
        \'singular_name\'     => _x( \'Blog\', \'taxonomy singular name\', \'textdomain\' ),
        \'search_items\'      => __( \'Search Blog Categories\', \'textdomain\' ),
        \'all_items\'         => __( \'All Blog Categories\', \'textdomain\' ),
        \'parent_item\'       => __( \'Parent Blog Category\', \'textdomain\' ),
        \'parent_item_colon\' => __( \'Parent Blog Category:\', \'textdomain\' ),
        \'edit_item\'         => __( \'Edit Blog Category\', \'textdomain\' ),
        \'update_item\'       => __( \'Update Blog Category\', \'textdomain\' ),
        \'add_new_item\'      => __( \'Add New Blog Category\', \'textdomain\' ),
        \'new_item_name\'     => __( \'New Blog Category Name\', \'textdomain\' ),
        \'menu_name\'         => __( \'Blog Categories\', \'textdomain\' ),
    );
    $args = array(
        \'hierarchical\'      => true,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        \'show_in_menu\'      => true,
        \'public\'            => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => array( \'slug\' => \'blogs\', \'with_front\' => true ),
    );
    register_taxonomy( \'blog\', array( \'post\' ), $args );
    $labels = array(
        \'name\'              => _x( \'Marketing Tags\', \'taxonomy general name\', \'textdomain\' ),
        \'singular_name\'     => _x( \'Marketing Tag\', \'taxonomy singular name\', \'textdomain\' ),
        \'search_items\'      => __( \'Search Marketing Tags\', \'textdomain\' ),
        \'all_items\'         => __( \'All Marketing Tags\', \'textdomain\' ),
        \'parent_item\'       => __( \'Parent Marketing Tag\', \'textdomain\' ),
        \'parent_item_colon\' => __( \'Parent Marketing Tag:\', \'textdomain\' ),
        \'edit_item\'         => __( \'Edit Marketing Tag\', \'textdomain\' ),
        \'update_item\'       => __( \'Update Marketing Tag\', \'textdomain\' ),
        \'add_new_item\'      => __( \'Add New Marketing Tag\', \'textdomain\' ),
        \'new_item_name\'     => __( \'New Marketing Tag Name\', \'textdomain\' ),
        \'menu_name\'         => __( \'Marketing Tag\', \'textdomain\' ),
    );
    $args = array(
        \'hierarchical\'      => false,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        \'show_in_menu\'      => true,
        \'public\'            => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => array( \'slug\' => \'marketing-tag\' ),
    );
    register_taxonomy( \'marketing-tag\', array( \'post\' ), $args );
    $labels = array(
        \'name\'              => _x( \'Video Playlists\', \'taxonomy general name\', \'textdomain\' ),
        \'singular_name\'     => _x( \'Video Playlist\', \'taxonomy singular name\', \'textdomain\' ),
        \'search_items\'      => __( \'Search Video Playlists\', \'textdomain\' ),
        \'all_items\'         => __( \'All Video Playlists\', \'textdomain\' ),
        \'parent_item\'       => __( \'Parent Video Playlist\', \'textdomain\' ),
        \'parent_item_colon\' => __( \'Parent Video Playlist:\', \'textdomain\' ),
        \'edit_item\'         => __( \'Edit Video Playlist\', \'textdomain\' ),
        \'update_item\'       => __( \'Update Video Playlist\', \'textdomain\' ),
        \'add_new_item\'      => __( \'Add New Video Playlist\', \'textdomain\' ),
        \'new_item_name\'     => __( \'New Video Playlist Name\', \'textdomain\' ),
        \'menu_name\'         => __( \'Video Playlist\', \'textdomain\' ),
    );
    $args = array(
        \'hierarchical\'      => true,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        \'show_in_menu\'      => true,
        \'public\'            => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => array( \'slug\' => \'video-playlist\' ),
    );
    register_taxonomy( \'video-playlist\', array( \'post\' ), $args );
    flush_rewrite_rules(true);
});
据我所知,它们都是正确创建的,并设置为公共,在菜单/ui中可见。它们在编辑帖子或通过管理员URL直接访问时都能正常工作,例如:

/wp-admin/edit-tags.php?taxonomy=blog
/wp-admin/edit-tags.php?taxonomy=marketing-tag
/wp-admin/edit-tags.php?taxonomy=video-playlist
但是,只有资源中心分类法显示在“管理”菜单的“帖子”下。其他人失踪:

admin menu

知道我的一些自定义分类法为什么没有显示在菜单中吗?虽然听起来很傻,但他们总是出现,不知怎么的,他们就消失了。

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

原来这是由一个插件引起的——我关闭了所有插件,并一次启用一个插件。最终,一种方法使自定义分类法再次消失。

这是导致问题的插件:https://wordpress.org/plugins/playbuzz/