Guide

Post Type Abilities

Abilities for creating and updating custom post types.


native-custom-fields/create-post-type

Creates a new custom post type and saves its configuration.

native-custom-fields/update-post-type

Updates the configuration of an existing custom post type.

Both abilities share the same execute_callback (savePostType) and the same input schema. If the post_type slug already exists, the record is updated; otherwise a new one is created.


Input Schema

{
  "type": "object",
  "required": ["post_type", "label"]
}

Properties

PropertyRequiredTypeDefaultDescription
post_typeYesstringPost type slug (lowercase, max 20 chars, underscores allowed)
labelYesstringPlural label (e.g. "Books")
singular_nameNostringlabel valueSingular label (e.g. "Book")
descriptionNostring""Description of the post type
menu_positionNointegernullAdmin menu position order
menu_iconNostring""Dashicons class or URL (e.g. "dashicons-book")
has_archiveNobooleanfalseWhether to enable an archive page
supportsNostring[]["title","editor","excerpt","comments","author","thumbnail","custom-fields"]WordPress features supported by this post type
taxonomiesNostring[][]Taxonomy slugs to register for this post type
publicNobooleantrueWhether the post type is publicly accessible
hierarchicalNobooleanfalseWhether the post type is hierarchical (like pages)
show_in_restNobooleantrueWhether to expose the post type in the WordPress REST API
map_meta_capNobooleantrueWhether to use the internal default meta capability handling

Valid supports Values

title, editor, excerpt, comments, author, thumbnail, custom-fields, revisions, page-attributes, post-formats, trackbacks


Output Schema

{
  "status": true,
  "message": "..."
}
FieldTypeDescription
statusbooleantrue on success, false on failure
messagestringResult description or error message

Internal Behaviour

  • post_type is sanitized with sanitize_key().
  • If supports is not provided, the default list is used.
  • Each value in the taxonomies array is sanitized with sanitize_key().
  • Builder slug format: native_custom_fields_post_type_builder_{post_type}
  • On success, the same values are also stored via OptionService::saveOptions().
  • Label strings (add_new_item, edit_item, etc.) are automatically generated from label and singular_name.

Auto-generated Visibility Settings

publicly_queryable: true
show_ui:            true
show_in_menu:       true
show_in_admin_bar:  true
show_in_nav_menus:  true
slug:       {post_type}
with_front: true
feeds:      false
pages:      true

Examples

Minimal

{
  "post_type": "book",
  "label": "Books"
}

Full

{
  "post_type": "book",
  "label": "Books",
  "singular_name": "Book",
  "description": "Book records for the library catalogue",
  "menu_position": 25,
  "menu_icon": "dashicons-book-alt",
  "has_archive": true,
  "public": true,
  "hierarchical": false,
  "show_in_rest": true,
  "supports": ["title", "editor", "thumbnail", "excerpt", "custom-fields"],
  "taxonomies": ["category", "post_tag"]
}

Success Response

{
  "status": true,
  "message": "Post type saved successfully."
}

Error Responses

{ "status": false, "message": "post_type is required." }
{ "status": false, "message": "label is required." }

Permission

Requires the manage_options WordPress capability.

Was this helpful?