Skip to content

Custom Taxonomy

Loïc Antignac edited this page May 24, 2022 · 4 revisions

Once the the plugin is created, the declaration(s) can be added:

<?php
/**
 * Plugin Name:       Example Custom Taxonomy
 * Author:            My Name
 * Text Domain:       wax-custom-content
 * Domain Path:       /languages
 */
defined( 'ABSPATH' ) || exit;

// If you already have an autoload (for example if you are on Bedrock) you can remove these 3 lines, otherwise leave them.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
	require __DIR__ . '/vendor/autoload.php';
}

use Webaxones\Core\Entities\Entities;

Webaxones\Core\Library::init( 'webaxones-content' );

/**
 * Custom Taxonomy: Project category
 */
$declarations[] = [
	'entity'   => 'Webaxones\Core\Classification\Taxonomy',
	'labels'   => [
		'gender'            => 'f',
		'name'              => _x( 'Project categories', 'Capitalized Plural Name', 'webaxones-content' ),
		'singular_name'     => _x( 'Project category', 'Capitalized Singular Name', 'webaxones-content' ),
		'parent_item_colon' => __( 'Parent project category: ', 'webaxones-content' ),
		'all_items'         => __( 'All project categories', 'webaxones-content' ),
		'new_item'          => __( 'New project category', 'webaxones-content' ),
		'the_singular'      => __( 'The project category', 'webaxones-content' ),
		'the_plural'        => __( 'The project categories', 'webaxones-content' ),
	],
	'settings' => [
		'slug'              => 'project-category',
		'hierarchical'      => false,
		'public'            => true,
		'show_admin_column' => true,
		'show_in_rest'      => true,
		'object_type'       => ['project'],
	],
];

Entities::process( $declarations );

Labels

Taxonomy entity has a gender key in the labels. The value is m (for masculine) by default.
All the labels can be translated from the 8 values presented in labels above.

Settings

As for all entities, settings starts with the slug key which identifies the entity and must be unique.
All arguments accepted by the register_taxonomy function can be added in settings.