Skip to content

Custom Taxonomy

1. Create Using CLI

General Command:
sh
php wp cxf-make:taxonomy {custom_taxonomy_name}
With Custom Post Type:
sh
php wp cxf-make:taxonomy {custom_taxonomy_name} --object={post_type_name}
  • {custom_taxonomy_name} → Your taxonomy name.
  • {post_type_name} → The custom post type name under which you want to set your taxonomy. If omitted, the default post type is post.
Naming Conventions:
  • UpperCamelCase: CustomTaxonomyName (Recommended)
  • camelCase: customTaxonomyName
  • snake_case: custom_taxonomy_name
  • kebab-case: custom-taxonomy-name
  • Mixed: customTaxonomy_Name, custom-taxonomy_name, Custom_taxonomy-name

INFO

All formats are converted to UpperCamelCase to follow the PSR-4 standard.

IMPORTANT

You cannot use Taxonomy as a name since it is a reserved word in the framework. Check reserved words here.

Example:
sh
php wp cxf-make:taxonomy PortfolioCategory

This command will generate all necessary files and directories to register the Taxonomy.

Expected CLI Response:
Success: The taxonomy PortfolioCategory's taxonomy directory has been created at ... <!-- Skipped if Taxonomies directory already exists -->
Success: The taxonomy PortfolioCategory's taxonomy file has been created at ...
Generated Files and Directories:
  • Taxonomy Directory (Skipped if Taxonomies directory already exists): /wp-content/plugins/codexshaper-framework/src/Taxonomies
  • Taxonomy File: /wp-content/plugins/codexshaper-framework/src/Taxonomies/PortfolioCategory.php

2. Using Option Builder

A powerful Option Builder allows easy creation of taxonomies.

Example: Creating portfolio-category taxonomy for portfolio post type.
php
use CodexShaper\Framework\Builder\CustomTaxonomy;

CustomTaxonomy::create(
    'custom_taxonomy',
    array(
        "taxonomy" => "custom_taxonomy",
        "name" => "Custom Taxonomies",
        "singular_name" => "Custom Taxonomy",
        "search_items" => "Search Custom Taxonomies",
        "all_items" => "All Custom Taxonomies",
        "parent_item" => "Parent Custom Taxonomy",
        "parent_item_colon" => "Parent Custom Taxonomy: ",
        "edit_item" => "Edit Custom Taxonomy",
        "update_item" => "Update Custom Taxonomy",
        "add_new_item" => "Add New Custom Taxonomy",
        "new_item_name" => "New Custom Taxonomy",
        "menu_name" => "Custom Taxonomy",
        "object_type" => array("portfolio"),
        "hierarchical" => true,
        "show_ui" => true,
        "show_admin_column" => true,
        "query_var" => true,
        "rewrite" => array(
            "slug" => "portfolio-categories", 
            "with_front" => false
        ),
        "public" => true,
        "publicly_queryable" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => false,
        "show_in_rest" => false,
    )
);
ArgumentTypeDefaultDescription
taxonomystring-The unique identifier (slug) for the taxonomy (e.g., custom_taxonomy).
namestring-Plural label for the taxonomy (e.g., “Books”).
singular_namestring-Singular label (e.g., “Book”).
search_itemsstring-Label for the search form placeholder (e.g., “Search Custom Taxonomies”).
all_itemsstring-Label to display for all taxonomy terms (e.g., “All Custom Taxonomies”).
parent_itemstring-Label for a parent taxonomy item (e.g., “Parent Custom Taxonomy”).
parent_item_colonstring-Label for parent taxonomy item with a colon (e.g., “Parent Custom Taxonomy:”).
edit_itemstring-Label for editing a taxonomy term (e.g., “Edit Custom Taxonomy”).
update_itemstring-Label for updating a taxonomy term (e.g., “Update Custom Taxonomy”).
add_new_itemstring-Label for adding a new taxonomy term (e.g., “Add New Custom Taxonomy”).
new_item_namestring-Label for a newly created taxonomy term (e.g., “New Custom Taxonomy”).
menu_namestring-Label for the taxonomy menu in the WordPress admin (e.g., “Custom Taxonomy”).
object_typearrayarray()An array of post types to which this taxonomy applies (e.g., array('portfolio')).
hierarchicalbooleanfalseIf true, the taxonomy behaves like categories (parent-child relationship). If false, it behaves like tags.
show_uibooleantrueIf true, the taxonomy is displayed in the WordPress admin UI.
show_admin_columnbooleanfalseIf true, displays the taxonomy in its own column on the post type listing screen.
query_varboolean|stringtrueEnables using the taxonomy’s name in WP queries (e.g., ?custom_taxonomy=term).
rewritearraytrueControls permalink structure (e.g., 'slug' => 'portfolio-categories').
publicbooleanfalseIf true, the taxonomy is publicly available (front-end queries, permalinks, etc.).
publicly_queryablebooleanMatches publicIf true, allows front-end queries.
show_in_menubooleanfalseIf true, displays the taxonomy in the admin menu.
show_in_nav_menusbooleanfalseIf true, allows this taxonomy to be used in navigation menus.
show_in_restbooleanfalseIf true, exposes the taxonomy in the WordPress REST API.

3. Creating from Dashboard

Navigate to CodexShaper Framework >> Custom Taxonomies.

Custom Taxonomy View

ArgumentTypeDefaultDescription
Taxonomy IDstring-The unique identifier (slug) for the taxonomy (e.g., custom_taxonomy).
Singular Namestring-Singular label (e.g., "Book").
Plural Namestring-Plural label for the taxonomy (e.g., “Books”).
Front Slugstring-A slug that can be used for the front-end (optional).
Select Objectstring-Choose the post type (e.g., post, portfolio, or custom post type).
Is PublicbooltrueToggle to set if the taxonomy is public.
Publicly QueryablebooltrueDetermines if this taxonomy can be queried in front-end requests.
Show in UIbooltrueChoose whether this taxonomy should appear in the UI.
Show in Admin MenubooltrueToggle to show or hide in admin menus.
Show in Nav MenuboolfalseToggle to show or hide in navigation menus.
Show in ResetboolfalseIf true, exposes the taxonomy in the WordPress REST API.
Is ActivebooltrueSet this to Yes to activate the taxonomy.

4. Creating Manually

Steps:
  1. Navigate to:
    sh
    {project_root}/wp-content/plugins/codexshaper-framework/src/Taxonomies
  2. Create a file using UpperCamelCase.php naming convention (e.g., PortfolioCategory.php).
  3. Open the file in a text editor and insert the following code:
php
<?php

namespace CodexShaper\Framework\Taxonomies;

use CodexShaper\Framework\Foundation\Taxonomy;

if (!defined('ABSPATH')) {
    exit();
}

class PortfolioCategory extends Taxonomy {
    public function __construct() {
        parent::__construct();
    }

    public function get_name() {
        return 'portfolio-category';
    }

    public function get_object_type() {
        return array('portfolio');
    }

    public function get_title() {
        return join(' ', array_map('ucfirst', explode('-', $this->taxonomy)));
    }

    public function is_public() {
        return true;
    }

    public function is_publicly_queryable() {
        return true;
    }

    public function is_hierarchical() {
        return true;
    }

    public function is_show_ui() {
        return true;
    }

    public function is_show_in_rest() {
        return true;
    }

    public function is_query_var() {
        return true;
    }

    public function is_show_in_menu() {
        return true;
    }

    public function is_show_in_nav_menus() {
        return true;
    }
}

Done! Your custom taxonomy is now registered.