Taxonomy makes groups of posts. Taxonomy enables you to a group of the post of similar characteristics.
In WordPress, Mainly two types of taxonomies are used. Both are inbuilt taxonomies.
- Tags
- Categories
Categories are Hierarchical Taxonomy, Whenever Tags are Non-Hierarchical Taxonomy.
Custom taxonomy
Many People know that WordPress is a blogging platform, But WordPress provides all facilities that one CMS framework provides. WordPress gives the facility to make custom taxonomy that enhances WordPress as a CMS framework. To make custom taxonomy WordPress has register_taxonomy() function.
<?php register_taxonomy( $taxonomy, $object_type, $args ); ?>
You can refer to this function to the https://developer.wordpress.org/reference/functions/register_taxonomy/. Use init
action hook to call this function.
Parameters:
$taxonomy (string) (Required):
The name of taxonomy. Taxonomy should contain only alphanumeric characters and underscore. .All letters should be in lower case. Taxonomy name character length is less than 32 characters.
$object_type (array/string)(required)
The name of the post type for this taxonomy. $object_type can be a built-in post or custom post type. WordPress default post types are post, page, revision, or nav_menu_item. If we want to associate this custom taxonomy $object_type parameter has a custom post type name.
$args (array)(optional)
An array of taxonomy setting array.
Arguments:
label (string)(optional) – The Plural name of this taxonomy.
labels (array)(optional) – An array of labels. For array labels, We consider hierarchical taxonomy as categories and non-hierarchical taxonomy as tags. If labels array is not passed or empty labels array passed, name element of labels array is set to label args element and sigular_name element of labels array is set to taxonomy name.
- name – Plural name of the taxonomy
- singular_name – Singular name of the taxonomy.
- menu_name – The text displayed in the menu. If menu_name is not given, menu_name is to name value.
- all_items – All Items Text.
- edit_item – Edit Item Text
- view_item -View Item Text
- edit_item – Edit Item text
- view_item – View Item Label
- update_item – Update Item Text
- add_new_item – Add new Item Text
- new_item_name – New Item Name Label Name
- parent_item – Parent Item Label. parent_item is only for hierarchical taxonomy. Default is Parent Category
- parent_item_colon -same as parent item but with colon, default is same as parent_item.
- search_item -search Item Text
- popular items – Popular Items Text
There are other argument elements. You can refer them to the https://developer.wordpress.org/reference/functions/register_taxonomy/#arguments.