Custom taxonomies
7 min read
A taxonomy is a way of grouping content. WordPress has two built in: Categories and Tags. A custom taxonomy adds your own, such as Genres for Books or Cities for Events. Each entry in a taxonomy is a term (for example "Fantasy").
Taxonomies are available on every plan. They work on any post type, including custom post types.
Two shapes exist:
Shape | Hierarchical setting | Looks like |
|---|---|---|
Category-style | On | Tick-boxes in the editor, terms can have a parent. |
Tag-style | Off | A free-text box with suggestions, no parents. |
Where to find it
Open WPM Fields › Taxonomies. Its list has these columns: Key, Plural label, Post types, Status and REST API. Click a row to edit it or Add taxonomy to create one.
Create a taxonomy
- Click Add taxonomy.
- Fill in Plural label ("Genres") and Singular label ("Genre").
- Check the Taxonomy key (filled in from the singular label until you edit it).
- Under Post types tick every type the taxonomy belongs to. The default is Post.
- Choose Hierarchical for category-style or leave it off for tag-style.
- Click Create taxonomy. You see "Taxonomy created."
The new taxonomy appears under each chosen post type's menu (or the Posts menu) as an extra screen.
The Basics section
Field | Default | What it does |
|---|---|---|
Plural label / Singular label | empty (required) | Menu and form wording. |
Taxonomy key | from the singular label | 1 to 20 characters: lowercase letters, numbers, hyphens, underscores. Cannot be changed after creation. |
Post types | Post | The post types the taxonomy is attached to. Lists public post types and other registered types except attachments and blocks. |
Public | On | "Show it in the admin and use it on the site (when the other settings allow)." |
Hierarchical | Off | "Like categories: terms can have a parent. Turn off for tag-style taxonomies." |
Active | On | When off the taxonomy is not registered. "Its terms stay in the database." |
Advanced settings | Off | Shows six tabs: General, Labels, Visibility, URLs, REST API, Permissions. |
Key rules
You will see these messages when something is wrong:
- "Taxonomy key is required."
- "Taxonomy key must be 1–20 characters: lowercase letters, numbers, hyphens, underscores only."
- "A taxonomy with this key already exists in Mass Custom Fields."
- "This taxonomy key is reserved by WordPress." Core taxonomies (
category,post_tag,post_format,nav_menu,link_categoryand others) and reserved query words (type,name,year,term,tag,searchand so on) are refused. - "This taxonomy is already registered by WordPress or another plugin."
Post type "key" does not exist.A post type you ticked is inactive or not registered.
Advanced tabs
General
Setting | Default | Effect |
|---|---|---|
Description | empty | Stored with the taxonomy. |
Keep term order | Off | "Terms keep the order they were assigned in (wp_set_object_terms())." Normally terms are sorted alphabetically. |
Default term | Off | "Create a default term that can't be deleted." Posts saved with no term in this taxonomy get it automatically. |
Term name | empty | Required when the default term is on: "Default term name is required when default term is enabled." |
Term slug | empty | Optional; generated from the name when empty. |
Term description | empty | Optional. |
The default term is created the first time the taxonomy is registered after you save it.
Labels
The same behaviour as for post types: 24 label fields show the generated default as a grey placeholder, an empty field uses the default, Regenerate from labels fills all with defaults (and stores them as overrides), Clear overrides empties them. See General and Labels.
Keys: name, singular_name, menu_name, all_items, edit_item, view_item, update_item, add_new_item, new_item_name, parent_item, parent_item_colon, search_items, popular_items, separate_items_with_commas, add_or_remove_items, choose_from_most_used, not_found, no_terms, items_list_navigation, items_list, most_used, back_to_items, item_link, item_link_description.
Visibility
Setting | Default | Effect |
|---|---|---|
Show in admin | On | Gives the taxonomy an admin screen. |
Show in the admin menu | On | Adds a menu entry under the post type. |
Show in navigation menus (Appearance → Menus) | On | Terms can be added to menus. |
Show in the Tag Cloud widget | On | Terms appear in the Tag Cloud widget. |
Show in Quick Edit and Bulk Edit | On | Lets editors set terms from the list screen. |
Show a column in post lists | Off | Adds a column with the terms on the post type's list screen. Recommended for most taxonomies. |
Meta box | Default (based on hierarchy) | The box on the post edit screen, see below. |
Meta box options:
Option | What editors get |
|---|---|
Default (based on hierarchy) | A checklist for hierarchical taxonomies, a tag box for flat ones. |
Categories meta box | Always the checklist. |
Tags meta box | Always the tag box. |
Custom callback | Your own function (name typed in Custom callback (PHP function name)). |
None | No box at all. Terms can still be set in code, by the REST API and from Quick Edit (if enabled). |
A custom callback must be a WordPress meta box function (post_categories_meta_box, post_tags_meta_box) or be allowed with the filter wpmcf/taxonomies/allowed_callbacks. Otherwise saving fails with "Meta box callback must be a WordPress meta box function or one allowed by the wpmcf/taxonomies/allowed_callbacks filter." Meta box sanitization callback (optional) follows the same rule.
add_filter( 'wpmcf/taxonomies/allowed_callbacks', function ( array $allowed, string $arg ) {
if ( 'meta_box_cb' === $arg ) {
$allowed[] = 'my_genre_meta_box';
}
return $allowed;
}, 10, 2 );URLs
Setting | Default | Effect |
|---|---|---|
Permalinks | Default (taxonomy key) | Default (taxonomy key), Custom slug or Disabled. Term pages live at |
Custom slug | empty | Only with Custom slug. |
Use the front URL prefix (with_front) | On | Includes your permalink prefix (for example |
Hierarchical URLs | Off | "For hierarchical taxonomies, include the parent slugs in term URLs." |
Publicly queryable | On | Term pages can be requested on the front end. |
Disable query variable | Off | Removes |
Custom query variable (optional) | empty | Replaces the key as the query variable. |
Changing URLs sets a rewrite flush that runs on the next page load. You do not need to resave Settings › Permalinks. See Custom post types.
REST API
Same four fields as for post types: Show in the REST API (On), REST base, REST namespace (wp/v2) and REST controller class (optional). Show in the REST API must be on for the block editor to show the taxonomy panel. See Permissions and REST API.
Permissions
Setting | Default | Effect |
|---|---|---|
Use default capabilities | On | "Recommended. WordPress decides who can manage and assign terms." |
Manage terms, Edit terms, Delete terms, Assign terms | empty | Shown when the default is off. Type the capability name required for each action, for example |
Update count callback (optional) | empty | A function that recalculates term counts. Allowed: |
Capability names are cleaned to lowercase letters, numbers, hyphens and underscores. Leave a field empty to keep WordPress's default for that action.
Attach a taxonomy to a post type
There are two equivalent ways:
- In the taxonomy: tick the post types under Post types.
- In the post type: tick the taxonomy under Taxonomies on the General tab (General and Labels). This is also how you add the built-in Categories or Tags to a custom type.
Taxonomies are registered before post types on every request, so the order of creation does not matter once both are saved. However, the two must exist when you save: you cannot attach a taxonomy to a post type that is inactive or does not exist yet.
Edit, deactivate and delete
- Edit: everything except the key. Click Save changes; you see "Taxonomy saved."
- Active off: the taxonomy is no longer registered. Terms and their assignments remain in the database but cannot be used.
- Delete (trash icon): "This removes the registration for «key». Terms and assignments may remain in the database." Existing terms are not deleted. Recreate a taxonomy with the same key to bring them back.
Use terms on your site
Taxonomies are registered with WordPress, so the usual functions work:
$terms = get_terms( array( 'taxonomy' => 'genre', 'hide_empty' => false ) );
$books = new WP_Query( array(
'post_type' => 'book',
'tax_query' => array(
array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'fantasy' ),
),
) );To store extra data on terms, create a field group with the Taxonomy location rule, see Field groups.
Hooks
wpmcf/taxonomies/before_register, wpmcf/taxonomies/register_args, wpmcf/taxonomies/after_register and wpmcf/taxonomies/allowed_callbacks work like their post type counterparts. See Hooks.
Troubleshooting
The taxonomy is not in the editor. Check Active, Show in admin, that the post type is ticked, and that Meta box is not "None". For the block editor, Show in the REST API must be on.
"Post type … does not exist." The post type is inactive, deleted, or created in the same moment. Save the post type first, reload, then attach it.
Term pages return 404. The permalink structure is Plain, the slug clashes with a page, or Publicly queryable is off. Wait for the next page load after a change.
The default term does not appear. Reload the admin once after saving; it is created on the next registration.
Still stuck? Contact support