Introduction
Like WordPress Posts, Connections Entries can have taxonomies such as Categories attached to them. The cn_register_taxonomy() function allows you to register new custom taxonomies that can be attached to Connections Entries.
This function automatically adds support for exporting and importing the custom taxonomy terms via the CSV Import addon, registers a Content Block to display the custom taxonomy terms attached to an Entry, and registers a Widget that can be added to the theme’s sidebar to display the custom taxonomy terms attached to an Entry.
If you are familiar with adding custom taxonomies to WordPress Posts using the register_taxonomy() function, this function has been modeled after it to provide you with familiarity and ease of use.
Functions
Registers a custom taxonomy.
cn_register_taxonomy( string $taxonomy, array $args = array() )
Note
Call on the Connections_Directory/Taxonomy/Init action hook.
Parameters
$taxonomy(string) (required) The taxonomy slug, must not exceed 32 characters.$args(array) (optional) The taxonomy parameters.labels(array) An array of labels for the taxonomy. By default, Tag labels are used for non-hierarchical taxonomies, and Category labels are used for hierarchical taxonomies.name(string) The taxonomy name, in the plural.- Default:
CategoriesorTags
- Default:
singular_name(string) The taxonomy name, in the singular.- Default:
CategoryorTag
- Default:
menu_name(string) The taxonomy name that is displayed in the admin sidebar menu.- Default:
CategoriesorTags
- Default:
search_items(string) The search items text.- Default:
Search CategoriesorSearch Tags
- Default:
all_items(string) The all items text.- Default:
All CategoriesorAll Tags
- Default:
select_items(string) The select all items text.- Default:
Select CategoriesorSelect Tags
- Default:
parent_item(string) The parent items text. This text is not used on non-hierarchical taxonomies.- Default:
Parent Categorywhen the taxonomy is hierarchical.
- Default:
parent_item_colon(string) The same asparent_item, but with a colon.- Default:
Parent Category:
- Default:
name_field_description(string) The description label displayed under the name field.- Default:
The name is how it appears on your site.
- Default:
slug_field_description(string) The description label displayed under the slug field.- Default:
The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.
- Default:
parent_field_description(string) The description label displayed under the parent field.- Default:
Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.
- Default:
desc_field_description(string) The description label displayed under the description field.- Default:
The description is not prominent by default; however, some themes may show it.
- Default:
edit_item(string) The edit item text.- Default:
Edit CategoryorEdit Tag
- Default:
view_item(string) The view item text.- Default:
View CategoryorView Tag
- Default:
update_item(string) The update item text.- Default:
Update CategoryorUpdate Tag
- Default:
add_new_item(string) The add new item text.- Default:
Add New CategoryorAdd New Tag
- Default:
new_item_name(string) The new item name text.- Default:
New Category NameorNew Tag Name
- Default:
not_found(string)- Default:
No categories found.orNo tags found.
- Default:
no_terms(string)- Default:
No categoriesorNo tags
- Default:
items_list_navigation(string)- Default:
Categories list navigationorTags list navigation
- Default:
items_list(string)- Default:
Categories listorTags list
- Default:
back_to_items(string) The text displayed after a taxonomy term has been updated as a link back to the term admin management page.content_block_option_name(string) The text displayed on the Settings admin page for the Content Block settings option name.content_block_heading(string) The text displayed as a heading above the taxonomy terms attached to the directory entry.content_block_label(string) The text display before the taxonomy terms attached to the directory entry.content_block_label_colon(string) The same ascontent_block_label, but with a colon.widget_name(string) The name of the widget displayed on the Widgets admin settings page.widget_description(string) The widget description displayed on the Widgets admin settings page.
description(string) Descriptive summary of what the taxonomy is for.public(bool) Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. The default settings ofpublicly_queryableandshow_uiare inherited frompublic.- Default:
true
- Default:
publicly_queryable(bool) Whether the taxonomy is publicly queryable. If not set, the default is inherited frompublic.hierarchical(bool) Whether the taxonomy is hierarchical.- Default:
false.
- Default:
show_ui(bool) Whether to generate and allow a UI for managing terms in this taxonomy in the admin. If not set, the default is inherited frompublic.show_in_menu(bool) Whether to show the taxonomy in the admin menu. Iftrue, the taxonomy is shown as a submenu. Iffalse, no menu is shown.show_uimust betrue. If not set, default is inherited fromshow_ui.register_content_block(bool) Whether or not to register a Content Block that will display a list of attached taxonomy terms. If not set, the default is inherited frompublic.- Default:
true
- Default:
register_widget(bool) Whether or not to register a widget that will display a list of attached taxonomy terms. If not set, the default is inherited frompublic.- Default:
true
- Default:
content_block_props(array) These parameters are optional and will be set automatically if theregister_content_blockparameter is set totrue. By default, Tag labels are used for non-hierarchical taxonomies, and Category labels are used for hierarchical taxonomies.name(string) The Content Block option name displayed on the Settings admin page.register_option(bool) Whether or not to register the option with the Settings API. Must be set totruein order to allow the Content Block to be shown on the Settings admin page.heading(string) The heading to display above the taxonomy terms list.
content_block_render_props(array) The properties that are to be passed to the taxonomy terms Content Block.container_tag(string) The HTML tag to be used for the Content Block container.- Default:
div
- Default:
label_tag(string) The HTML tag to be used for the taxonomy term label element.- Default:
span
- Default:
item_tag(string) The HTML tag to be used for the taxonomy term element.- Default:
span
- Default:
type(string) The display type to be used to display the taxonomy terms.- Accepts:
blockorlist - Default:
block
- Accepts:
list(string) If thetypeis alist, which type?- Accepts:
orderedorunordered - Default:
unordered
- Accepts:
label(string) The label to be displayed before the taxonomy terms.- Default:
Categories:
- Default:
separator(string) The taxonomy term separator used when separating taxonomy terms whentypeislist.- Default: ‘
,‘
- Default: ‘
parent_separator(string) The separator to be used when displaying the taxonomy term’s hierarchy.- Default: ‘
»‘
- Default: ‘
link(bool) Whether or not render the taxonomy terms as permalinks.- Default:
false
- Default:
parents(bool) Whether or not to display the taxonomy term hierarchy.- Default:
false
- Default:
child_of(int) The taxonomy term ID to retrieve child terms of.- Default:
0
- Default:
meta_box_cb(callable) Provide a callback for the admin metabox display. If no callback is defined the default taxonomy term metabox will be utilized.meta_box_sanitize_cb(callable) Callback for sanitizing taxonomy data saved from a metabox. If no callback is defined, default sanitization will be applied based the taxonomy is hierarchical or not.capabilities(array)manage_terms(string)- Default:
connections_manage_{$this->name}
The variable part of the name is the taxonomy slug.
- Default:
edit_terms(string)- Default:
connections_edit_{$this->name}
The variable part of the name is the taxonomy slug.
- Default:
delete_terms(string)- Default:
connections_delete_{$this->name}
The variable part of the name is the taxonomy slug.
- Default:
assign_terms(string)- Default:
connections_assign_{$this->name}
The variable part of the name is the taxonomy slug.
- Default:
rewrite(true|array) Registers rewrites for the taxonomy. To prevent rewrite rules from being registered, set tofalse.- Default:
true - Accepted array parameters:
hierarchical(bool) Default:falseslug(string) Default:$taxonomyslug.
- Default:
query_var(string|bool) Define the query variable key for the taxonomy.- Default:
$taxonomyslug
- Default:
update_count_callback(callable) Not yet implemented.show_in_rest(bool) Not yet implemented.rest_base(string) Not yet implemented.rest_controller_class(string) Not yet implemented.default_term(array|string) The default term to use for the taxonomy.name(string) The term name.slug(string) The term slug.description(string) The term description.
sort(bool) Not yet implemented._builtin(bool) Internal property, do not use or the sky will fall.
Example
Register a “Disciplines” hierarchical taxonomy.
add_action(
'Connections_Directory/Taxonomy/Init',
static function() {
cn_register_taxonomy(
'discipline',
array(
'hierarchical' => true,
'query_var' => 'cn-discipline',
'rewrite' => array( 'slug' => 'cn-discipline' ),
'public' => true,
'show_ui' => true,
'content_block_render_props' => array(
'type' => 'list',
'label' => '',
),
'labels' => array(
'name' => 'Disciplines',
'singular_name' => 'Discipline',
'search_items' => 'Search Disciplines',
'all_items' => 'All Disciplines',
'select_items' => 'Select Disciplines',
'parent_item' => 'Parent Discipline',
'parent_item_colon' => 'Parent Discipline:',
'edit_item' => 'Edit Discipline',
'view_item' => 'View Discipline',
'update_item' => 'Update Discipline',
'add_new_item' => 'Add New Discipline',
'new_item_name' => 'New Discipline Name',
'not_found' => 'No disciplines found.',
'no_terms' => 'No disciplines',
'items_list_navigation' => 'Disciplines list navigation',
'items_list' => 'Disciplines list',
'back_to_items' => '← Go to Disciplines',
'content_block_option_name' => 'Disciplines',
'content_block_heading' => 'Disciplines',
'content_block_label' => 'Disciplines',
'content_block_label_colon' => 'Disciplines:',
'widget_name' => 'Entry Disciplines',
'widget_description' => 'Entry Disciplines',
),
)
);
}
);
Hooks
Actions
Connections_Directory/Taxonomy/InitCustom Taxonomies should be registered on this action hook.Connections_Directory/Taxonomy/Registry/RegisteredConnections_Directory/Taxonomy/Registry/Unregistered
Widget
Connections_Directory/Taxonomy/Widget/Form/BeforeConnections_Directory/Taxonomy/Widget/Form/AfterConnections_Directory/Taxonomy/Widget/BeforeConnections_Directory/Taxonomy/Widget/After
Filters
Connections_Directory/Taxonomy/Set_PropertiesConnections_Directory/Taxonomy/Labels/{$taxonomy->name}Connections_Directory/Taxonomy/Register/Content_Block/IDConnections_Directory/Taxonomy/Register/Widget/ID
Widget
Connections_Directory/Taxonomy/Widget/Default_OptionsConnections_Directory/Taxonomy/Widget/Form/InstanceConnections_Directory/Taxonomy/Widget/UpdateConnections_Directory/Taxonomy/Widget/InstanceConnections_Directory/Taxonomy/Widget/Block
