Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Custom Taxonomies

Jared Cobb edited this page Jan 7, 2018 · 4 revisions

Overview

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

Example Class

There is an example class in /includes/taxonomies/class-example-taxonomy.php

Creating A Class

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.

Methods

get_taxonomy_args()

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.