Create a Custom Taxonomy for Custom Post Type
Oct 5, 2020 | WordPress
// Taxonomy for Custom Post Type
function staff_custom_taxonomy() {
$labels = array(
'name' => _x( 'Taxonomies', 'taxonomy general name' ),
'singular_name' => _x( 'Taxonomy', 'taxonomy singular name' ),
'search_items' => __( 'Search Taxonomies' ),
'all_items' => __( 'All Taxonomies' ),
'parent_item' => __( 'Parent Taxonomy' ),
'parent_item_colon' => __( 'Parent Taxonomy:' ),
'edit_item' => __( 'Edit Taxonomy' ),
'update_item' => __( 'Update Taxonomy' ),
'add_new_item' => __( 'Add New Taxonomy' ),
'new_item_name' => __( 'New Taxonomy Name' ),
'menu_name' => __( 'Taxonomies' ),
);
register_taxonomy('types',array('staff'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'taxonomy' ),
));
}
add_action( 'init', 'staff_custom_taxonomy', 0 );
This will make categories that only the assigned CPT can use.