显示不在子菜单中的自定义分类

时间:2016-04-18 作者:Lukas Vosylius

我有一个小问题,我找不到答案。。。我已经创建了自定义帖子类型和自定义分类法,但我的自定义分类法显示为自定义pos类型下的子菜单,下面是 example what I need 我该怎么做???以下是我的分类法和帖子类型的注册方式:

<?php

function inkodus_register_taxonomy() {
    // set up labels
    $labels = array(
        \'name\'              => \'Manufactures\',
        \'singular_name\'     => \'Manufacture\',
        \'search_items\'      => \'Search Manufactures\',
        \'all_items\'         => \'All Manufactures\',
        \'edit_item\'         => \'Edit Manufacture\',
        \'update_item\'       => \'Update Manufacture\',
        \'add_new_item\'      => \'Add New Manufactures\',
        \'new_item_name\'     => \'New Manufactures\',
        \'menu_name\'         => \'Manufactures\'
    );
    // register taxonomy
    register_taxonomy( \'manufactures\', \'manufactures\', array(
        \'hierarchical\'      => true,
        \'labels\'            => $labels,
        \'query_var\'         => true,
        \'show_admin_column\' => false,
        \'show_ui\'           => true
    ) );
}
add_action( \'init\', __NAMESPACE__ . \'\\\\inkodus_register_taxonomy\' );

function inkodus_create_post_type() {

    //setting up labels
    $labels = array(
        \'name\'                  => \'Furnitures-systems list\',
        \'singular_name\'         => \'Furniture-system\',
        \'add_new\'               => \'Add New System\',
        \'add_new_item\'          => \'Add New Furniture-System\',
        \'edit_item\'             => \'Edit System\',
        \'new_item\'              => \'New Furniture-system\',
        \'all_items\'             => \'All Systems\',
        \'view_item\'             => \'View System\',
        \'search_items\'          => \'Search furniture-systems\',
        \'not_found\'             => \'Furniture systems not found\',
        \'not_found_in_trash\'    => \'Furniture systems found in Trash\',
        \'parent_item_colon\'     => \'\',
        \'menu_name\'             => \'Furniture Systems
        \',
    );

    //registering post type
    register_post_type( \'furnituresystem\', array(
            \'labels\'                => $labels,
            \'has_archive\'           => true,
            \'public\'                => true,
            \'supports\'              => array( \'title\', \'editor\'), //\'excerpt\', \'custom-fields\', \'thumbnail\',\'page-attributes\' ),
            \'taxonomies\'            => array(\'manufactures\' ),
            \'exclude_from_search\'   => false,
            \'capability_type\'       => \'post\',
            \'rewrite\'               => array( \'slug\' => \'furnituresystem\' ),
            \'register_meta_box_cb\'  => \'add_attributes_metabox\'
        )
    );
}
add_action( \'init\', __NAMESPACE__ . \'\\\\inkodus_create_post_type\' );

?>

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

那么,你想补充的是manufactures 分类法product 职位类型Woocommerce Plugin?

改变manufactures 对象类型到product 它应该会起作用。

register_taxonomy( \'manufactures\', \'product\', array(
    \'hierarchical\'      => true,
    \'labels\'            => $labels,
    \'query_var\'         => true,
    \'show_admin_column\' => false,
    \'show_ui\'           => true
) );

SO网友:Abad Rahman

如果希望在products post type下使用分类法,则必须从更改代码。

register_taxonomy( \'manufactures\', \'manufactures\', array(
    \'hierarchical\'      => true,
    \'labels\'            => $labels,
    \'query_var\'         => true,
    \'show_admin_column\' => false,
    \'show_ui\'           => true
) );

register_taxonomy( \'manufactures\', \'products\', array(
    \'hierarchical\'      => true,
    \'labels\'            => $labels,
    \'query_var\'         => true,
    \'show_admin_column\' => false,
    \'show_ui\'           => true
) );
如果要将其添加到多个帖子类型,请使用帖子类型数组。看见register taxonomy 用于对象类型。

另请参见register_post_type 分类学注释。如果分类法在注册时与post类型没有关联,那么在使用过滤器(如parse_querypre_get_posts.