Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Since WordPress 2.3, plugin and theme authors have had the ability to create custom taxonomies-- essentially specialized "categories"-- to help organize information.

Custom taxonomy's are great when you want to create a list of terms for a specific post type. For example, let's say we have a custom post type of books and we want a custom taxonomy to go along with that.

All we have to do is add this code:

<?
add_action( 'init', 'authors_tax_init' );

function authors_tax_init() {
    // create an author taxonomy
    register_taxonomy(
        'author_tax',
        'books',
        array(
            'label' => __('Author Names'),
            'sort' => true,
            'args' => array('orderby' => 'term_order'),
            'rewrite' => array('slug' => 'author_names')
        )
    );
}
add_action( 'init', 'genre_tax_init' );

function genre_tax_init() {
    // create a genre taxonomy
    register_taxonomy(
        'genre_tax',
        'books',
        array(
            'label' => __('Genre Types'),
            'sort' => true,
            'args' => array('orderby' => 'term_order'),
            'rewrite' => array('slug' => 'genres')
        )
    );
}
?>

This code will create 2 new taxonomy types; one called Author Names and the other for Genre Types.

All you have to do is insert this into your theme's functions.php (create if it does not exist) or make it a plugin alongside with the custom post types found here Custom Post Type Wiki

This wiki article is best used with the following wiki article as well Custom Post Types

history | excerpt history