Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created April 4, 2013 10:09
Show Gist options
  • Save psdtohtml5/5309266 to your computer and use it in GitHub Desktop.
Save psdtohtml5/5309266 to your computer and use it in GitHub Desktop.
WordPress : Register Taxonomy Hierarchical
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_book_taxonomies', 0 );
//create two taxonomies, genres and writers for the post type "book"
function create_book_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => __( 'Genre' )
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' )
);
register_taxonomy( 'genre', array( 'book' ), $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment