bricks_register_post_type

Phase 2AdvancedComplexity: 7/10
Register a custom post type with labels and settings

Overview

Registers a custom WordPress post type (CPT) by generating a PHP file in the child theme. The CPT becomes available in the WordPress admin, REST API, and Bricks Builder immediately after registration. The generated file is placed in the child theme’s bricks-mcp/ directory and auto-loaded on every page load.

The supports array controls which editor features (title, editor, thumbnail, excerpt, etc.) are available for the post type. After registration, use bricks_create_post to populate it with content and bricks_create_template to create archive/single templates.

Key Features

PHP File Generation
Creates a standalone PHP file in the child theme that registers the post type on every page load.
Configurable Supports
Choose which editor features to enable: title, editor, thumbnail, excerpt, custom-fields, page-attributes, revisions, comments, author.
REST API Ready
Registered CPTs are automatically available via the WordPress REST API for external integrations.
Archive Support
Optional archive page with customizable slug. Enable has_archive to get a /slug/ archive URL.
Auto Rewrite Flush
Rewrite rules are flushed automatically after registration so the new URLs work immediately.

When to Use

When the site needs a custom content type (portfolio, team members, services, testimonials, tools, events)
Before creating templates that display custom content types
When you need a content type with a dedicated archive page
Before using bricks_create_post to populate content for the new type
Prerequisites
A child theme must be active (or will be created with bricks_ensure_child_theme) for the PHP file to be placed

When NOT to Use

When the standard post or page types are sufficient
When a plugin already provides the needed post type (e.g., WooCommerce products)
For temporary data — use custom database tables instead

Parameters

9 Total Parameters4 Required5 Optional
slugstringREQUIRED
Post type slug. Lowercase, max 20 chars, no spaces (e.g., "portfolio", "team_member", "mcp_tool").
labelstringREQUIRED
Plural label shown in admin menu (e.g., "Portfolios", "Team Members").
singular_labelstringREQUIRED
Singular label (e.g., "Portfolio", "Team Member"). Note: TS sends singular_label but PHP expects "singular" — auto-mapped.
descriptionstringoptional
Description of the post type for admin reference.
iconstringoptional
Dashicon or custom icon for the admin menu (e.g., "dashicons-portfolio", "dashicons-groups"). Note: TS sends "icon" but PHP expects "menu_icon" — auto-mapped.
Default: dashicons-admin-post
supportsarrayREQUIRED
Array of editor features the post type supports.
Values: title, editor, thumbnail, excerpt, custom-fields, page-attributes, revisions, comments, trackbacks, author
has_archivebooleanoptional
Whether the post type has an archive page at /slug/.
Default: false
publicly_queryablebooleanoptional
Whether queries can be performed on the front end.
Default: true
hierarchicalbooleanoptional
Whether the post type is hierarchical like pages (supports parent/child relationships).
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 Portfolio CPT

Creates a Portfolio custom post type with archive support, thumbnails, and excerpts. Available at /portfolio/ archive URL.

JSON
bricks_register_post_type({
  slug: "portfolio",
  label: "Portfolios",
  singular_label: "Portfolio",
  description: "Client project showcase",
  icon: "dashicons-portfolio",
  supports: ["title", "editor", "thumbnail", "excerpt"],
  has_archive: true
})

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 "singular_label" but the PHP endpoint expects "singular". The client maps this automatically, but if directly calling the PHP API, use "singular". Similarly, "icon" maps to "menu_icon" in PHP.

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
Post type slugs must be lowercase, max 20 characters, with no spaces. Use underscores for multi-word slugs (e.g., "team_member" not "team member").

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 registered CPT with has_archive=true needs an archive template and single template in Bricks to display properly. Use bricks_create_template after registration.

Tips & Warnings

Tips & Warnings

Known parameter mismatch: The TypeScript tool sends singular_label and icon, but the PHP endpoint expects singular and menu_icon. The client handles this mapping internally. If you need to manually edit the generated PHP file, look in {child-theme}/bricks-mcp/.

After registration: Follow up with bricks_register_taxonomy to add categories/tags, bricks_create_post to populate content, and bricks_create_template for archive and single templates.

Return Values

FieldTypeDescription
successbooleanWhether the post type was registered successfully
slugstringThe registered post type slug
filestringPath to the generated PHP file in the child theme
messagestringConfirmation message

Related Tools

Technical Details

Tool ID
bricks_register_post_type
API Endpoint
/post-types
HTTP Method
POST
Namespace
wordpress-site
Source File
wordpress/post-types.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release
20250101