-
Notifications
You must be signed in to change notification settings - Fork 1
Overview of Taxonomy Model
Carlos Moreira edited this page Jun 2, 2020
·
2 revisions
The model for a Taxonomy will define how it will behave and to what post type it will be associated with.
For a model to be recognized as a taxonomy model, it should have the parameter type set to 'category' or 'tag'. If it's set to 'category' it will automatically be an hierarchical category, as opposed to 'tag' which will not be hierarchical.
Example:
return [
'type' => 'tag',
'name' => 'country',
'labels' => [
'has_one' => 'Country',
'has_many' => 'Countries',
'overrides' => [
'labels' => [
'menu_name' => 'Places',
]
],
],
// args - third parameter for register_taxonomy
'options' => [
'description' => 'Description for this taxonomy',
'public' => true,
'show_in_menu' => true,
],
// object_type - second parameter for register_taxonomy
'associations' => [
'book',
'post',
],
];
Available parameters and description:
| Parameter | Description |
|---|---|
| type |
string - ‘category’ // or 'tag' to set it to non-hierarchical automatically |
| name |
string - identifier of this taxonomy |
| associations |
string/array - to what CPT(s) it should be associated |
| labels |
array - Everything related with labels for this custom post type (More Info Soon) |
| options |
array - Refer to the third parameter for register_taxonomy function from WordPress |