Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Created August 14, 2019 06:44
Show Gist options
  • Save dotherightthing/f31b95d368a415d0c3d19dc3f8e1d6ed to your computer and use it in GitHub Desktop.
Save dotherightthing/f31b95d368a415d0c3d19dc3f8e1d6ed to your computer and use it in GitHub Desktop.
[Taxonomies] Some taxonomies are obvious, others less so. Here are some notes for thinking about taxonomies. #wordpress

Taxonomies

Created: 2017.07.06

Essentially, a taxonomy is a way of classifying data. Typically a taxonomy will have a set of characteristics that is unique to it - A Basic Explanation of WordPress Taxonomies

Category

Taxonomies apply to posts and pages - and anything else

If you're not attaching your taxonomy to posts, then you may not get the interface created for you. Taxonomies are generic, after all, you could create one for any sort of object - Taxonomies

You can create Custom Taxonomies for any content type in WordPress - WORDPRESS 3.1 FOR DESIGNERS

Not Part of Custom Post Types, though typically used with them - WORDPRESS 3.1 FOR DESIGNERS

Sub category

Posts can live in multiple categories - A Basic Explanation of WordPress Taxonomies

You don't register "child" or "parent" taxonomies. You add (child-)terms to a hierarchical taxonomy - How to register child taxonomies?

Each tag or category you create is a “term” within that taxonomy. For example, if you create a category “Movies” (in our site about entertainment), “Movies” becomes a term within the category taxonomy. - A Basic Explanation of WordPress Taxonomies

UI

In a post, each taxonomy appears as a meta box.

In this box:

  • Each category created within that Taxonomy in the Admin UI has a checkbox
  • Each term programmatically added with wp_insert_term has a checkbox

These items are output as siblings. This does not mirror the intended hierarchy.

Adding separate taxonomies creates separate meta boxes, but this makes authoring cumbersome.

From a UX perspective, I don't want to have to select taxonomic terms like 'Tour Leg' at the post level. I only want to drill down from the Tour, (optionally) to the Tour Leg, so that I understand the context of the latter.

With Don't Believe The Hype:

  • A Tour post may be within a Tour leg - metabox
  • A Tour post must be within a Tour - programmatic or metabox
  • A Tour must be within a Tour region - programmatic

My usage

I use custom taxonomies with custom post types, to:

  • assign ACF fields to those specific taxonomies
  • avoid polluting non-tour posts with tour specific ACF baggage

Example: Don't Believe The Hype

The three levels of context provide users with multiple ways to find information.

  • The structure favoured by the site owner (taxonomy provides context)
  • Internal or external Search (post name and custom post type slug provides context)
  • The site menus (custom post type provides context)

1. Post Name: Stage

This provides context when the taxonomy is not present / the filter is inactive.

  • place1-to-place2 (tour stage)

The catchy page title is reserved for the Heading 1.

The SEO page title is reserved for the <title> element.

2. Custom Post Type (CPT): Tour Diaries (tourdiaries)

A grouping or collection of posts of a non-generic type. The CPT provides some structure, but finding a specific post could be difficult without the context provided by the taxonomy. On the other hand, if the user is not interested in reading a tour sequentially, browsing the Tour Diaries in a flat form might be preferable.

The CPT slug should be specific enough to differentiate this content, and make sense at any level that the user drills down to.

A plural slug and name are most appropriate.

This is why tours is not an appropriate CPR. A diary entry is not a tour. But tourdiaries is appropriate, because every post is a page in the diary.

  • Slug: tourdiaries
  • Every day is a tour diary
  • A diary is semantically also a collection of diary entries
  • Out-of-the-box, a WordPress CPT comes with: single post view (single-tourdiaries.php), index view (archive-tourdiaries.php)

3. Custom Taxonomy (CT): Tours (%tours%)

A grouping or collection of terms or classifications which can be used to filter or classify posts. The CPT provides some structure, but finding a specific post could be difficult without the context provided by the taxonomy. On the other hand, if the user is not interested in reading a tour sequentially, browsing the Tour Diaries in a flat form might be preferable.

Defined first, but sits parallel to the Custom Post Type. Could be queried separately?

A plural slug and name are most appropriate.

  • Slug: %tours%, replaced by the assigned tour Term (e.g. east-asia-2015) or Hierarchical Terms (e.g. east-asia-2015/mongolia)
  • Out-of-the-box, a WordPress CT comes with: index view (taxonomy-tour.php)

An optional classification or filter. Like a folder structure, but one that can be 'folded up'. In other words, all of the following contexts are 'true':

  1. /tourdiaries/east-asia-2015/china-1/1/place1-to-place2 (the post is a diary of a sequential day, from a regional tour/leg, that is part of a global tour)
  2. /tourdiaries/east-asia-2015/place1-to-place2 (the post is a diary of a day, from a specific global tour) (folded once)
  3. /tourdiaries/place1-to-place2 (the post is a diary of a day, from a tour) (folded twice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment