Menu

WordPress Taxonomies on Steroids

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.

Built in Taxonomies

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

Custom taxonomies

Their URL:

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.

Default taxonomies

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

Taxonomies Theme Templates

Here are the options.

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

Output custom taxonomy to a template

get_the_term_list()
get_the_terms()

<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>

WP Taxonomy Generator
Codex – Taxonomies
Codex – Register taxonomy
How To Create A Custom Taxonomy In WordPress