分类链接不显示在自定义管理菜单wordpress


Taxonomy link not showing in custom admin menu wordpress

我找到了很多解决方案,但我的情况完全不同。

现在我的问题是,我正在制作一个插件,在插件中我制作自定义帖子类型和自定义分类法,首先它的鼻涕虫是不同的,现在我想要的post type slug和taxonomy slug是相同的,我也成功地实现了这一点,但有一个问题,那就是我的类别链接没有显示在管理菜单中,因为当我注册分类法时,我设置object_type为slug,这在post type slug和taxonomy slug中是相同的,但当我将对象类型更改为post type name category menu时,显示完美。

这是我的代码

帖子类型代码:

add_action('init', 'kbe_articles');
function kbe_articles() {
    $labels = array(
        'name'                  => __('Articles', 'kbe'),
        'singular_name'         => __('Articles', 'kbe'),
        'all_items'             => __('Articles', 'kbe'),
        'add_new'               => __('New Article', 'kbe'),
        'add_new_item'          => __('Add New Article', 'kbe'),
        'edit_item'             => __('Edit Article', 'kbe'),
        'new_item'              => __('New Article', 'kbe'),
        'view_item'             => __('View Articles', 'kbe'),
        'search_items'          => __('Search Articles', 'kbe'),
        'not_found'             => __('Nothing found', 'kbe'),
        'not_found_in_trash'    => __('Nothing found in Trash', 'kbe'),
        'parent_item_colon'     => ''
    );
    $kbe_rewrite = array(
        'slug'                => KBE_PLUGIN_SLUG,
        'with_front'          => false,
        'pages'               => true,
        'feeds'               => true,
    );
    $args = array(
        'labels'                => $labels,
        'public'                => true,
        'publicly_queryable'    => true,
        'show_ui'               => true,
        'query_var'             => true,
        'menu_icon'             => WP_Articles.'images/icon-kbe.png',
        'capability_type'       => 'post',
        'hierarchical'          => false,
        'menu_position'         => 3,
        'supports'              => array('title','editor','thumbnail','comments'),
        'rewrite'               => $kbe_rewrite,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => true
    );
    register_post_type( 'kbe_articles' , $args );
    flush_rewrite_rules();
}

分类代码:

add_action( 'init', 'kbe_taxonomies');
function kbe_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => __( 'Articles Category', 'kbe'),
        'singular_name'     => __( 'Articles Category', 'kbe' ),
        'search_items'      => __( 'Search Articles Category', 'kbe' ),
        'all_items'         => __( 'All Articles Categories', 'kbe' ),
        'parent_item'       => __( 'Parent Articles Category', 'kbe' ),
        'parent_item_colon' => __( 'Parent Articles Category:', 'kbe' ),
        'edit_item'         => __( 'Edit Articles Category', 'kbe' ),
        'update_item'       => __( 'Update Articles Category', 'kbe' ),
        'add_new_item'      => __( 'Add New Articles Category', 'kbe' ),
        'new_item_name'     => __( 'New Articles Category Name', 'kbe' ),
    );  
    register_taxonomy( 'kbe_taxonomy', array(KBE_PLUGIN_SLUG), array(
        'hierarchical'          => true,
        "label"                 => 'Categories',
        "singular_label"        => "Articles Category",
        'show_ui'               => true,
        'show_admin_column'     => true,
        'show_in_nav_menus'     => true,
        'show_tagcloud'         => true,
        'query_var'             => true,
        'rewrite'               => array( 'slug' => KBE_PLUGIN_SLUG, 'with_front' => true ),
    ));
    flush_rewrite_rules();
}

下面是代码所以我的post type和taxonomy slug是一样的

function taxonomy_slug_rewrite($wp_rewrite) {
    $rules = array();
    $taxonomies = get_taxonomies(array('_builtin' => false), 'objects');
    $post_types = get_post_types(array('public' => true, '_builtin' => false), 'names');
    foreach ($post_types as $post_type) {
        $post_type_data = get_post_type_object( $post_type );
        $post_type_slug = $post_type_data->rewrite['slug'];
        foreach ($taxonomies as $taxonomy) {
            if ($taxonomy->object_type[0] == $post_type_slug) {
                $categories = get_categories(array('type' => $post_type_slug, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0));
                /* @var $category type */
                foreach ($categories as $category) {
                    $rules[$post_type_slug . '/' . $category->slug . '/?$'] = 'index.php?' . $category->taxonomy . '=' . $category->slug;
                }
            }
        }
    }
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'taxonomy_slug_rewrite' );
下面是我的菜单代码:
add_action('admin_menu', 'kbe_plugin_menu');
function kbe_plugin_menu() {
    add_submenu_page('edit.php?post_type=kbe_articles', 'Order', 'Order', 'manage_options', 'kbe_order', 'wp_kbe_order');
    add_submenu_page('edit.php?post_type=kbe_articles', 'Settings', 'Settings', 'manage_options', 'kbe_options', 'wp_kbe_options');
}

现在当我更改register_taxonomy( 'kbe_taxonomy', array('kbe_articles'),时,我的分类法链接出现在管理自定义菜单中,但当我更改register_taxonomy( 'kbe_taxonomy', array(KBE_PLUGIN_SLUG),时,分类法链接从菜单中消失。

我该怎么做才能使我的分类法链接出现在菜单中。但不能改变鼻涕虫

好的,这就是答案。

我在条件

上添加了一个子菜单下面是我的代码:
add_submenu_page('edit.php?post_type=foo_articles', 'Categories', 'Categories', 'manage_options', 'edit-tags.php?taxonomy=foo_taxonomy&post_type=foo_articles');