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');