The Difference Between Hierarchical and Non-Hierarchical Taxonomies?

The simple answer is that terms in hierarchical taxonomies can have child terms. But what else?

‘hierarchical’=>false

When you specify a 'hierarchical'=>false you get the following type of metabox which is the metabox format WordPress also uses for Post Tags:

Taxonomy Term Metabox in the Post Edit Screen when $hierarchical==false

‘hierarchical’=>true

However when you specify 'hierarchical'=>true you get the following type of metabox which is the metabox format WordPress also uses for Categories:

Taxonomy Term Metabox in the Post Edit Screen when $hierarchical==true

Of course the example above also points out where hierarchical categorization can be a bit of a mixed bag because in real life subcategories often apply to many parent categories. Even so alowing “many parents” is not how hierarchical taxonomies works in WordPress but IMO categorizing anything perfectly is almost impossible regardless of how WordPress works. So Caveat Emptor!

On Custom Taxonomy Registration, or “Why Won’t it Save?”

While not directly related to the question if you are a newbie trying out custom taxonomies, (or an experienced dev who isn’t paying attention like happened to me when I wrote this up!) it’s likely that you’ll try adding register_taxonomy() like the code you see in the question directly into your theme’s functions.php file. Oops!

If you do add the code directly into functions.php your metabox will display but it won’t save your newly added terms (and in the 'heirarchical'=>true form of the metabox your existing terms won’t load with checkboxes.) That’s because you need to register custom taxonomies (and custom post types) inside an init hook, like so:

<?php
add_action('init','register_movie_genre_taxonomy');
  function register_movie_genre_taxonomy() {
    register_taxonomy('movie-genre', 'movie', array(
      'hierarchical'    => true,
      'label'           => 'Movie Genre',
      'query_var'       => 'movie-genre',
      'rewrite'         => array('slug' => 'genres' ),
    ));
}

Hope this helps!

Leave a Comment