bricks_register_taxonomy

Phase 2IntermediateComplexity: 6/10
Register a custom taxonomy for a post type

Overview

Registers a custom WordPress taxonomy and associates it with one or more post types. The taxonomy can be hierarchical (category-like with parent/child relationships) or flat (tag-like). A PHP file is generated in the child theme’s bricks-mcp/ directory and auto-loaded on every page load.

After registration, create terms with bricks_create_term and assign them to posts with bricks_assign_terms. Use {post_terms_TAXONOMY} dynamic tag to display terms on the frontend.

Key Features

Hierarchical or Flat
Set hierarchical=true for category-like terms with parent/child relationships, or false for flat tag-like terms.
Multi-Post-Type Support
Attach the taxonomy to multiple post types at once (e.g., both "portfolio" and "case_study").
PHP File Generation
Creates a standalone PHP file in the child theme that registers the taxonomy on every page load.
Auto Rewrite Flush
Rewrite rules are flushed automatically so taxonomy archive URLs work immediately.

When to Use

After registering a CPT that needs categorization or tagging
When posts need to be grouped, filtered, or sorted by custom criteria
Before creating query filters that filter by taxonomy terms
When building a filterable portfolio, directory, or catalog
Prerequisites
The post type(s) the taxonomy will be attached to should be registered first via bricks_register_post_type

When NOT to Use

When the built-in categories and tags are sufficient for your post type
When you need a simple custom field — use ACF fields instead of a taxonomy
When the taxonomy is only for internal organization — consider post meta instead

Parameters

5 Total Parameters4 Required1 Optional
slugstringREQUIRED
Taxonomy slug. Lowercase, max 32 chars (e.g., "project_type", "skill", "tool_category").
labelstringREQUIRED
Plural label (e.g., "Project Types", "Skills").
singular_labelstringREQUIRED
Singular label (e.g., "Project Type", "Skill"). Note: TS sends singular_label but PHP expects "singular" — auto-mapped.
object_typesarrayREQUIRED
Post type slugs this taxonomy applies to (e.g., ["portfolio"], ["post", "page"]). Note: TS sends "object_types" but PHP expects "post_types" — auto-mapped. Falls back to ["post"] if missing.
hierarchicalbooleanoptional
Whether terms can have parent-child relationships. true = categories, false = tags.
Default: false

Code Examples


Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12

Register a Hierarchical Taxonomy

Creates a hierarchical taxonomy for the portfolio post type. Terms can have parent/child relationships like categories.

JSON
bricks_register_taxonomy({
  slug: "project_type",
  label: "Project Types",
  singular_label: "Project Type",
  object_types: ["portfolio"],
  hierarchical: true
})

Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12

Register a Flat Taxonomy for Multiple Types

Creates a flat tag-like taxonomy shared between portfolio items and team members.

JSON
bricks_register_taxonomy({
  slug: "skill",
  label: "Skills",
  singular_label: "Skill",
  object_types: ["portfolio", "team_member"],
  hierarchical: false
})

Common Mistakes


Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
The TypeScript tool accepts "object_types" but the PHP endpoint expects "post_types". The client maps this internally. If the mapping fails, the taxonomy falls back to being attached to ["post"] only. Verify the attachment by checking the generated PHP file.

Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
A taxonomy without terms is useless. Follow up with bricks_create_term to add the initial terms, then bricks_assign_terms to associate them with posts.

Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49