Custom Taxonomies in WordPress

Define a Custom Taxonomy

add_action( 'init', 'ww_create_taxonomies' );
function ww_create_taxonomies()
{
    // Add new taxonomy, NOT hierarchical (like tags)
    register_taxonomy(
        'ww_languages',    // Unique ID for the "Languages" taxonomy. (always use a prefix)
        'ww_products',     // The post-type(s) this taxonomy can be applied-to .
        array(
            'hierarchical'                      => false,
            'labels' => array(
                'name'                          => _x( 'Languages', 'taxonomy general name' ),
                'singular_name'                 => _x( 'Language', 'taxonomy singular name' ),
                'search_items'                  => __( 'Search Languages' ),
                'popular_items'                 => __( 'Popular Languages' ),
                'all_items'                     => __( 'All Languages' ),
                'parent_item'                   => null,  // Not needed because 'hierarchical' is false.
                'parent_item_colon'             => null,  // Not needed because 'hierarchical' is false.
                'edit_item'                     => __( 'Edit Language' ),
                'update_item'                   => __( 'Update Language' ),
                'add_new_item'                  => __( 'Add New Language' ),
                'new_item_name'                 => __( 'New Language Name' ),
                'separate_items_with_commas'    => __( 'Separate languages with commas' ),
                'add_or_remove_items'           => __( 'Add or remove languages' ),
                'choose_from_most_used'         => __( 'Choose from the most used languages' ),
                'not_found'                     => __( 'No languages found.' ),
                'menu_name'                     => __( 'Languages' ),
            ),
            'show_ui'                           => true,
            'show_admin_column'                 => true,
            'update_count_callback'             => '_update_post_term_count',
            'query_var'                         => true,
            'rewrite'                           => array( 'slug' => 'languages' ),
        )
    );
}

Custom Taxonomy Template Files Hierarchy

taxonomy-{taxonomy ID}-{taxonomy-term}.php
taxonomy-{taxonomy ID}.php
taxonomy.php
archive.php
index.php


Sources