Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I've been developing a complex CPT lately and something came up that made me realize I need a second custom Taxonomy on the CPT. Is this impossible? Also I'm currently using tags as well, so the second taxonomy can't be subbed out for tags.

Any advice is greatly appreciated.

share|improve this question
1  
It's possible, just create it the same way as your normal Taxonomies. –  Howdy_McGee Sep 26 '13 at 13:45
    
Is this something that you've tested and used before? Because when I created a secondary custom taxonomy, the second one replaced the newest one in the menu. –  user741166 Sep 30 '13 at 15:26
    
Yes recently actually. I'll post my taxonomy below to test against yours. –  Howdy_McGee Sep 30 '13 at 16:30
add comment

1 Answer

First off, what Wordpress version are you using? Second, here's a Custom Post Type with 2 Taxonomies. It is a bit lengthy as I am copy / pasting it straight from one of my projects, feel free to view the codex and add or omit things as you see fit.

First I register the post type - following the standards.

/** Create Post Type **/
function CPT_init(){
    // Products CPT 
    register_post_type('product', array(
        'labels'            =>  array(
            'name'          =>      __('Products'),
            'singular_name' =>      __('Product'),
            'all_items'     =>      __('View Products'),
            'add_new'       =>      __('New Product'),
            'add_new_item'  =>      __('New Product'),
            'edit_item'     =>      __('Edit Product'),
            'view_item'     =>      __('View Product'),
            'search_items'  =>      __('Search Products'),
            'no_found'      =>      __('No Products Found'),
            'not_found_in_trash' => __('No Products in Trash')
                                ),
        'public'            =>  true,
        'publicly_queryable'=>  true,
        'show_ui'           =>  true, 
        'query_var'         =>  true,
        'show_in_nav_menus' =>  false,
        'capability_type'   =>  'post',
        'hierarchical'      =>  false,
        'rewrite'           =>  array('with_front' => false),
        'menu_position'     =>  21,
        'supports'          =>  array('title','editor', 'thumbnail'),
        'has_archive'       =>  true
    )); 
}
add_action('init', 'CPT_init');

Next I create the 2 taxonomies for my Custom Post Type - Products

One will be for Product Categories and the other will be for Product Manufacturers.

/** Add Custom Taxonomy **/
function product_category_taxonomy() {
    $labels = array(
        'name'              => __( 'Product Categories' ),
        'singular_name'     => __( 'Product Category' ),
        'search_items'      => __( 'Search Product Categories' ),
        'all_items'         => __( 'All Product Categories' ),
        'parent_item'       => __( 'Parent Product Category' ),
        'parent_item_colon' => __( 'Parent Product Category:' ),
        'edit_item'         => __( 'Edit Product Category' ), 
        'update_item'       => __( 'Update Product Category' ),
        'add_new_item'      => __( 'Add New Product Category' ),
        'new_item_name'     => __( 'New Product Category' ),
        'menu_name'         => __( 'Product Categories' ),
    ); 
    $args = array(
        'labels'            => $labels,
        'public'            =>  true,
        'hierarchical'      =>  true,
        'show_in_nav_menus' =>  false,
        'has_archive'       =>  true
    );
    register_taxonomy( 'protax', 'product', $args ); 

    $labels = array(
        'name'              => __( 'Manufacturers' ),
        'singular_name'     => __( 'Manufacturer' ),
        'search_items'      => __( 'Search Manufacturers' ),
        'all_items'         => __( 'All Manufacturers' ),
        'parent_item'       => __( 'Parent Manufacturer' ),
        'parent_item_colon' => __( 'Parent Manufacturer:' ),
        'edit_item'         => __( 'Edit Manufacturer' ), 
        'update_item'       => __( 'Update Manufacturer' ),
        'add_new_item'      => __( 'Add New Manufacturer' ),
        'new_item_name'     => __( 'New Manufacturer' ),
        'menu_name'         => __( 'Manufacturer' ),
    );
    $args = array(
        'labels'            => $labels,
        'public'            =>  true,
        'hierarchical'      =>  true,
        'show_in_nav_menus' =>  false,
        'has_archive'       =>  true
    );
    register_taxonomy( 'mantax', 'product', $args ); 
}
add_action( 'init', 'product_category_taxonomy');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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