6.3.3.12. Taxonomies Section

This section contains settings that are used to save values into taxonomies [2] either by retrieving the values from the target post page or entering them manually.

TL;DR

  • The values of taxonomies are called terms and taxonomy terms create a set, which means that duplicate values are not allowed inside a taxonomy.
  • Taxonomies must be registered to WordPress via PHP so that terms can be added to a taxonomy. They cannot be defined arbitrarily like post meta keys (See: Post Meta Section). If a taxonomy is not registered to WordPress, you cannot add a term into that taxonomy arbitrarily.
  • Name of a taxonomy can be found by looking at the URL of the page that displays the terms of that taxonomy. For example, the relative URL of Tags page of WordPress is wp-admin/edit-tags.php?taxonomy=post_tag and the taxonomy name used to store post tags is post_tag. Examples are shown in Table 6.1. You can also use this method to understand if the values shown in a page are taxonomy terms.

Taxonomies are used by plugins, themes, and WordPress itself to extend the functionality of WordPress. Two of the most commonly used and known taxonomies are post tags and post categories. It is safe to say that a taxonomy is used to group certain things. For example, category taxonomy is used to group the category names. Likewise, post_tag taxonomy is used to group post tags. Taxonomies do not allow duplicate values. For example, when you add the same tag into two different posts, they actually refer to the same entry in the database. By this way, it is possible to show all posts having the same tags or categories easily. Also, taxonomies must be registered to WordPress before a value can be saved into a taxonomy. This registration is done by the plugins and themes, in their codes.

Important

While post meta keys (See: Post Meta Section) can be created arbitrarily, taxonomies must be registered to WordPress. This registration is done by the plugins and the themes in their source codes. One cannot save a value into a non-registered taxonomy.

Now, let’s check out the post_tag taxonomy which is used to save tags of the posts. As you probably already know, the existing post tags can be seen by clicking Posts > Tags link that exist in the sidebar of the admin panel of WordPress. In this page, all tags, their descriptions and slugs, and how many posts use those tags are shown. An example is shown in Fig. 6.21.

../../../_images/post-tags-example.png

Fig. 6.21 A list of post tags shown in the Tags page of WordPress

Each value of a taxonomy is called a term and the terms are stored in wp_terms table [1]. So, the tags shown in Fig. 6.21 are stored in wp_terms table, as shown in Fig. 6.22.

../../../_images/post-tags-wp_terms-table.png

Fig. 6.22 Post tags in wp_terms table

The taxonomies which the terms belong to are stored in wp_term_taxonomy table [1]. This is shown in Fig. 6.23. As you can see, term_id in wp_term_taxonomy table refers to term_id in wp_terms table.

../../../_images/post-tags-wp_term_taxonomy-table.png

Fig. 6.23 Taxonomies of post tags stored in wp_term_taxonomy table

To link the terms with the posts, wp_term_relationships table [1] is used. Fig. 6.24 shows the entries related to the tags shown in Fig. 6.21. object_id column stores the IDs of the posts that use the term. term_taxonomy_id refers to term_taxonomy_id column in wp_term_taxonomy table.

../../../_images/post-tags-wp_term_relationships-table.png

Fig. 6.24 object_id in wp_term_relationships table links the terms to the posts

In Fig. 6.24, there is no entry having term_taxonomy_id of 23, because the tag named as My tag 3 is not used by any post. You can also see in Fig. 6.21 that My tag 3’s count is 0.

Now you know how the taxonomies are stored in the database and how they are linked to the posts. Now, let’s look at how we can find the name of a taxonomy. The name of the taxonomy actually exists in the URL of the page that shows a list of terms registered to the taxonomy. For example, the relative URL of Tags page of WordPress is wp-admin/edit-tags.php?taxonomy=post_tag. Here, the query string of the URL, which is taxonomy=post_tag, shows the taxonomy name, post_tag. This is also valid for other pages showing a list of terms of a taxonomy. A few examples are shown in Table 6.1.

Table 6.1 Example pages showing a list of terms of a taxonomy and their relative URLs. Bold parts of relative URLs show the name of the taxonomy.
Page (Plugin/Theme) Relative URL
Products > Categories (WooCommerce) wp-admin/edit-tags.php?taxonomy=product_cat&post_type=product
Products > Tags (WooCommerce) wp-admin/edit-tags.php?taxonomy=product_tag&post_type=product
Movies > Collections (WP Movie Library) wp-admin/edit-tags.php?taxonomy=collection&post_type=movie
Posts > Categories (WordPress) wp-admin/edit-tags.php?taxonomy=category
Posts > Tags (WordPress) wp-admin/edit-tags.php?taxonomy=post_tag

As it is shown in Table 6.1, you can easily find the name of the taxonomy by simply looking at the URL of the page that shows the terms inside that taxonomy. Moreover, this is also a nice way to understand whether values shown in a page are terms or not. So, if you see taxonomy in the query string of the URL of a page, you can say that the values displayed in that page are actually terms of a taxonomy, whose name is written in the URL of the page.

Now, you know everything that should be known to use the settings under this section.

6.3.3.12.1. Custom Taxonomy Value Selectors

Using this setting, you can save anything from the target post page as a value (term) of a taxonomy. This is a type of Selector and Attribute Setting. Additional inputs are explained as follows.

Multiple?

By default, the first found values will be used. If you want to use all values found by a CSS selector, check this checkbox.

Let’s say you defined three input groups by clicking to button. The following table shows how many values will be saved when this checkbox is checked and not checked for these three hypothetical input groups. Found value counts are just examples.

Inputs Saved value count when
Input group Found value count Checked Not checked
1 5 5 1
2 12 12 1
3 1 1 1
Append?

If you want to append to any previously-existing values, check this checkbox. Otherwise, the found value will remove all of the previously-existing values of its taxonomy.

Tip

If you use the same taxonomy name in more than one input group, the input groups except the first one must have this checkbox checked. Otherwise, the values saved by previous input groups of this setting will be deleted.

Taxonomy name
Enter the name of the taxonomy which the found value should be saved into as a term. For example, if this is a post category, you can write category (Table 6.1) into this field. For more information about taxonomies, see Taxonomies Section.

Note

The plugin will automatically generate a unique slug when saving a term. If a term with the same value already exists, it will not be recreated. Instead, the existing term will be used.

6.3.3.12.2. Custom Taxonomy Value

Using this setting, you can manually add a term into a taxonomy. The inputs of this setting are explained as follows.

Append?
See Custom Taxonomy Value Selectors
Taxonomy name
See Custom Taxonomy Value Selectors
Taxonomy value
Enter the value that should be saved as a term into the taxonomy whose name is given in the taxonomy name input.

Footnotes

[1](1, 2, 3) https://codex.wordpress.org/Database_Description
[2]https://wordpress.org/support/article/taxonomies/