0

I have one small problem and I can't find answer...I have created custom post type and custom taxonomy, but my custom taxonomy is showing as sub menu under custom pos type, here is example what I need how can I do this??? here is how my taxonomy and post type is registered:

<?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 Answers 2

0

So, what you are trying is to add manufactures taxonomy for product post type of Woocommerce Plugin?

Change manufactures object type to product and it should work.

register_taxonomy( 'manufactures', 'product', array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'query_var'         => true,
    'show_admin_column' => false,
    'show_ui'           => true
) );
7
  • I want add Manufactures as menu item with icon and so on..not as sub menu in Furniture systems menu Commented Apr 18, 2016 at 9:58
  • You can't register a taxonomy in the menu. It doesn't belong to any post type. So, what is it used for?
    – Minh Tri
    Commented Apr 18, 2016 at 10:07
  • there is no other way to do display custom taxonomy in the menu? Commented Apr 18, 2016 at 10:27
  • Yes, no way if it is a taxonomy. Btw, what is it used for?
    – Minh Tri
    Commented Apr 18, 2016 at 10:33
  • To create manufactures list Commented Apr 19, 2016 at 8:19
0

If you want the taxonomy under products post type then you must change your code from.

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

to

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

If you want to add this to multiple post types then use an array of post types. See register taxonomy for object type.

Also see register_post_type notes on taxonomy. If the taxonomy is not associated with the post type at the point of registration then this could issues when using filters such as parse_query or pre_get_posts.

1
  • I want add Manufactures as menu item with icon and so on..not as sub menu in Furniture systems menu Commented Apr 18, 2016 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.