“Season,” “Brand,” “Service area”—custom taxonomies classify posts along axes of your own choosing. You get the same mechanism as categories and tags, under whatever name you like.
function my_register_taxonomies() {
register_taxonomy('season', ['shohin'], [
'label' => 'Season',
'public' => true,
'hierarchical' => true, // true = category-style / false = tag-style
'show_admin_column' => true, // add a column to the admin list
'show_in_rest' => true, // use it in the block editor
]);
}
add_action('init', 'my_register_taxonomies');The first argument is the taxonomy name; the second is the post types to attach it to (an array lets you name several). That alone adds a “Season” selector to the product editing screen.
TipsHow to create custom post types (register_post_type)Want to create the custom post type first?Category-style and tag-style
One line—hierarchical—changes its character entirely.
hierarchical: true (category-style) | hierarchical: false (tag-style) | |
|---|---|---|
| Parent/child | Supported | Not supported |
| Editing screen | Chosen with checkboxes | Added by free text entry |
| What it suits | Fixed classifications (season, area, industry) | Keywords that keep growing (material, features) |
“I want people to pick from a predetermined set” means category-style; “I want writers to add freely” means tag-style. Choose based on how the people running the site will work.
Argument cheat sheet
| Argument | Meaning | Common values |
|---|---|---|
label / labels | The name shown in the admin screen | 'Season' |
public | Whether it appears on the site | true |
hierarchical | Whether it can have parents and children | true / false |
show_admin_column | Whether to add a column to the post list | true |
show_in_rest | Block editor support | true |
rewrite | The URL shape | ['slug' => 'season', 'with_front' => false] |
show_in_nav_menus | Whether it can be added to menus | true |
meta_box_cb | Change the input UI | false hides the panel |
query_var | Whether it can filter via URL parameter | true |
Archive pages and templates
Registering a taxonomy automatically creates an archive page per term.
/season/winter/ ← a list of posts belonging to "Winter"The template responsible for that page is looked for in this order.
taxonomy-season-winter.php(that specific term only)taxonomy-season.php(the whole taxonomy)taxonomy.phparchive.phpindex.php
archive.php stands in even without a dedicated file, so confirm it works first and add files as you need them.
You can output the term’s name and description in the template like this.
<h1><?php single_term_title(); ?></h1>
<?php if ($desc = term_description()) : ?>
<div class="term-desc"><?php echo wp_kses_post($desc); ?></div>
<?php endif; ?>TipsTemplate hierarchy cheat sheet (which file gets used?)The big picture of the template hierarchy, in this cheat sheetShowing a post’s terms
Output the terms attached to a post with get_the_terms() (or the_terms() if you want the HTML too).
<?php the_terms(get_the_ID(), 'season', 'Season: ', ', '); ?>To build a list of the classification itself (a filter menu), use get_terms().
Fetching only that term’s posts
When you’re building a list yourself, filter with tax_query.
$query = new WP_Query([
'post_type' => 'shohin',
'tax_query' => [
['taxonomy' => 'season', 'field' => 'slug', 'terms' => 'winter'],
],
]);TipsFiltering by category and taxonomy with tax_queryHow to write tax_query conditions (AND/OR, multiple taxonomies)Choosing between taxonomies and custom fields
Both are “extra information,” but their roles differ.
- Taxonomy—an axis for filtering lists. You get a dedicated archive page and URL, and filtering is fast
- Custom field—a value displayed within the article. Price, size, date and so on
The rule of thumb is “do I want to browse a list by this data?” “I want to see only winter products” means a taxonomy; “I just want to display a price” means a custom field. It also makes a speed difference as content grows.
TipsFiltering and sorting by custom field with meta_queryHow to filter by custom field, and a note on speedNaming rules and cautions
- Lowercase alphanumerics and underscores, up to 32 characters
- Avoid names WordPress uses—
category,post_tag,type,author,name,date,termsand others - Don’t use the same name as a post type (the URLs collide)
Attaching it to a post type later
To use an existing taxonomy on another post type as well, one line does it.
add_action('init', function () {
register_taxonomy_for_object_type('season', 'post'); // use "Season" on posts too
});Conversely, to use the standard categories and tags on a custom post type, 'taxonomies' => ['category', 'post_tag'] in register_post_type() is the easy route.
Summary
- Just run
register_taxonomy('name', ['post type'], [...])on theinithook hierarchicaldecides category-style (pick from a set) or tag-style (add freely)taxonomy-<name>.phphandles the archive. Without it,archive.phpstands in- Axes you want to filter by are taxonomies; values you only display are custom fields
Once you can design classifications, the same article data can be presented in many different ways.