-
Notifications
You must be signed in to change notification settings - Fork 5
Custom Taxonomies
Creating a Custom Taxonomy Class is how you map a CCB Entity's properties to a Custom Taxonomy in WordPress. Custom Taxonomies must be linked (related) to a Custom Post Type. CCB Core includes several Custom Taxonomy Classes by default, just a few are: CCB_Core_Group_Area
, CCB_Core_Group_Tag
, CCB_Core_Calendar_Event_Type
, etc.
Class | Entity Property | Post Type | Hierarchical |
---|---|---|---|
CCB_Core_Group_Area |
area |
ccb_core_group |
Yes |
CCB_Core_Group_Tag |
childcare_provided |
ccb_core_group |
No |
CCB_Core_Calendar_Event_Type |
event_type |
ccb_core_calendar |
Yes |
There is an example class in /includes/taxonomies/class-example-taxonomy.php
You can create your own classes to implement your own mappings of CCB Entity properties to Custom Taxonomies
All Custom Taxonomy Classes inhert from (extend) a parent class called CCB_Core_Taxonomy
. Your class is required to implement one method which helps to define the mappings and functionality.
This method should return an array of $args
that define this new WordPress Custom Taxonomy. These are the same $args
that are used by register_taxonomy
.
In addition to the normal register_taxonomy
args, there is one other property that must be included called api_mapping
.
If a taxonomy is hierarchical (like a category) you simply map to the property on the CCB Entity like so:
'api_mapping' => 'event_type'
If a taxonomy is non-hierarchical (like a tag) you map an array of key / value pairs like so:
'api_mapping' => [
'childcare_provided' => 'Childcare Provided'
]
This may be a little confusing. But non-hierarchical taxonomies (tags) are typically either set as true
or false
on the CCB Entity. So in this case we check whether childcare_provided
is true
, and if so, create a "tag" with a value of "Childcare Provided" in WordPress.