December 20, 2013

WordPress Custom Taxonomy Example

WordPress Custom Taxonomy Example:

$_tType = 'Taxonomy Type';
$_tSlug = 'wp-taxonomy-type';
$_tId = str_replace(' ', '_', strtolower($_tType));
register_taxonomy($_tId, 'post', array(
'hierarchical' => true,
'labels' => array(
'name' => _x( $_tType, 'taxonomy general name' ),
'singular_name' => _x( $_tType, 'taxonomy singular name' ),
'search_items' =>  __( 'Search '.$_tType ),
'all_items' => __( 'All '.$_tType ),
'parent_item' => __( 'Parent '.$_tType ),
'parent_item_colon' => __( 'Parent '.$_tType.':' ),
'edit_item' => __( 'Edit '.$_tType ),
'update_item' => __( 'Update '.$_tType ),
'add_new_item' => __( 'Add New '.$_tType ),
'new_item_name' => __( 'New '.$_tType ),
'menu_name' => __( $_tType ),
),
'rewrite' => array(
'slug' => $_tSlug,
'with_front' => false,
'hierarchical' => true
),
));
//register_taxonomy_for_object_type( $_tId, 'another-post-type');

Last updated: March 19, 2014