Menu

WordPress Taxonomy – Your Custom Categories and Tags

June 3, 2017 - WordPress

Taxonomies are generally based either on Categories (hierarhical) or on Tags (non-hierarhical) and can be included in default or custom post types.

Default Taxonomies

WordPress offers four built-in taxonomies out of the box:
Categories and Navigation menu which are hierarhical.
Tags and Links are multifaceted.

Custom Taxonomies

Custom Taxonomies can be applied to one or several post types, including posts and can have custom index & archive.

Their URL is:

xxx.com/location/carribean                 // location is taxonomy
xxx.com/hotel-review/hotel-ocean    // hotel-review is custom post type

Like with post types, we need to decide where to put taxonomy – in the plugin or in the theme.

Taxonomies in the Database

Taxonomies are saved in wp_term_taxonomy table in the database.
wp_term_taxonomy table

Taxonomy terms are saved in wp_terms table in the database.
wp_terms table

Taxonomies Theme Templates

Here are the options.

taxonomy-{taxonomy}-{slug}.php
taxonomy-{taxonomy}.php
taxonomy.php

Output Custom Taxonomy to a Template

<div class="taxonomies">
        <div class="product-type">
                        <?php echo get_the_term_list($post->ID, 'product-type', 'Type of Product: ', ',', ''); ?>
        </div>
        <div class="price-range">
                        <?php echo get_the_term_list($post->ID, 'price', 'Price Range: ', ',', ''); ?>
        </div>
        <div class="satisfaction">
                        <?php echo get_the_term_list($post->ID, 'satisfaction', 'Satisfaction: : ', ',', ''); ?>
        </div>
</div>