WordPress taxonomies FAQ
A taxonomy is a way to classify and categorize content, such as posts, pages, and custom post types, by creating a hierarchical structure of terms.
The most common taxonomies in WordPress are categories and tags, but developers can also create custom taxonomies.
Categories are a hierarchical taxonomy, meaning that they can have parent and child terms. For example, a “Fruits” category can have “Apples” and “Oranges” as child terms.
Tags, on the other hand, are a non-hierarchical taxonomy, meaning that they don’t have parent-child relationships. They are simply a way to group related posts together.
register_taxonomy function is a built-in WordPress function that allows users to create custom taxonomies for their WordPress site beyond the default categories and tags that are included with WordPress.
To use the
register_taxonomy function, users need to provide several arguments to define the properties of the custom taxonomy. These arguments include the name of the taxonomy, the types of objects that the taxonomy will be applied to (such as posts or pages), and labels for the taxonomy (such as the singular and plural forms of the term).
Once the custom taxonomy has been registered using the
register_taxonomy function, it can be used in a similar way to the default categories and tags. Users can create new terms within the taxonomy, and assign those terms to individual pieces of content on their site. This allows for more fine-grained organization and classification of content.
WordPress taxonomies are stored in the database as terms, and the relationship between the terms and the content (posts, pages, custom post types) is stored in the
Each taxonomy has its own set of terms, and each term has a unique ID. When a post is associated with a term, the term’s ID and the post’s ID are added to the
wp_term_relationships table, along with the ID of the taxonomy to which the term belongs.
In addition to the
wp_term_relationships table, WordPress also uses other tables to store information about taxonomies, such as
wp_term_taxonomy table stores metadata about the taxonomy, such as the number of times a term is used, and whether the taxonomy is hierarchical. The
wp_terms table stores the name, slug, and description of each term in the taxonomy.
Go to the official WordPress documentation and check the
register_taxonomy() function reference.