March 12, 2015 at 5:37 am
#5967
Jim Gaiko
Participant
There’s no other plugin involved – the custom taxonomy and custom post type are created from within functions.php. Here’s the code that creates the taxonomy:
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_skilltype_hierarchical_taxonomy', 0 );
//create a custom taxonomy name it topics for your posts
function create_skilltype_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Skill Types', 'taxonomy general name' ),
'singular_name' => _x( 'Skill Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Skill Types' ),
'all_items' => __( 'All Skill Types' ),
'parent_item' => __( 'Parent Skill Type' ),
'parent_item_colon' => __( 'Parent Skill Type:' ),
'edit_item' => __( 'Edit Skill Type' ),
'update_item' => __( 'Update Skill Type' ),
'add_new_item' => __( 'Add New Skill Type' ),
'new_item_name' => __( 'New Skill Type' ),
'menu_name' => __( 'Skill Types' ),
);
// Now register the taxonomy
register_taxonomy('skilltype',array('skills'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'skilltype' ),
));
}