I have created a custom post type for adding employees. I have added the category taxonomy for it. Then I have added a category named “Employees” (slug: employees). But when I add a new employee, it shows me all the categories to choose. How can I restrict it to show only “Employees” category here?
Here is my php code in functions.php:
function employees_register() {
$labels = array(
'name' => _x('Employees', 'post type general name'),
'singular_name' => _x('Employee', 'post type singular name'),
'add_new' => _x('Add New', 'employees'),
'add_new_item' => __('Add New Employee'),
'edit_item' => __('Edit Employee'),
'new_item' => __('New Employee'),
'view_item' => __('View Employee'),
'search_items' => __('Search Employee'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'taxonomies' => array( 'category' ),
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'employees' , $args );
}
add_action('init', 'employees_register');
You should register custom taxonomies with the register_taxonomy() function:
https://codex.wordpress.org/Function_Reference/register_taxonomy
Then, only these taxonomies will show as options for the post type, rather than Categories of other post types.