Skip to content

[DRAFT] Templates / DataViews: Show declared post types for templates #76020

Draft
Mayank-Tripathi32 wants to merge 3 commits into
WordPress:trunkfrom
Mayank-Tripathi32:add/template-post-types-column
Draft

[DRAFT] Templates / DataViews: Show declared post types for templates #76020
Mayank-Tripathi32 wants to merge 3 commits into
WordPress:trunkfrom
Mayank-Tripathi32:add/template-post-types-column

Conversation

@Mayank-Tripathi32

@Mayank-Tripathi32 Mayank-Tripathi32 commented Feb 27, 2026

Copy link
Copy Markdown
Member

Closes #75670 (Still WIP exploration)

What?

Closes
Adds a Post Types column to the Templates DataViews list, showing which post types each template is associated with (as defined via postTypes in theme.json custom templates).

Why?

Template postTypes data is already defined in theme.json and used internally for filtering, but it was never exposed in the REST API or surfaced in the Site Editor's template list UI. This makes it difficult for users to see at a glance which templates are available for which post types.

How?

WIP - Needs discussion on proper way we could get this backported.

  • Gutenberg_REST_Templates_Controller_7_0: Added post_types to prepare_item_for_response() — returns the template's post_types array (or an empty array if not set). Added get_item_schema() to register post_types as a readonly array-of-strings field.
  • Gutenberg_REST_Static_Templates_Controller: Extended get_item_schema() to include the same post_types property for the registered-templates endpoint.
  • template-activate.php: After building a template from file via _build_block_template_result_from_file(), the postTypes data from the theme file is now propagated onto the template object so it's available for serialization.

Testing Instructions

  1. Activate a theme that defines custom templates with postTypes in its theme.json (e.g., a theme with entries like "postTypes": ["post"] or "postTypes": ["post", "page"] under customTemplates).
  2. Navigate to Appearance → Editor → Templates.
  3. Switch to Table layout.
  4. Verify a "Post Types" column appears showing the associated post types for each template.
  5. Templates with postTypes defined should show the types as a comma-separated list (e.g., post or post, page).
  6. Templates without postTypes defined should show an em dash ().
  7. Switch to a theme that does not define any postTypes on its custom templates.
  8. Verify the "Post Types" column does not appear at all.

Testing via REST API

  1. Make a GET request to /wp/v2/templates (or /wp/v2/registered-templates).
  2. Verify each template object includes a post_types field.
  3. Custom templates with postTypes in theme.json should return the array (e.g., ["post"]).
  4. Templates without postTypes should return an empty array ([]).

Testing Instructions for Keyboard

  1. Navigate to the Templates list using keyboard (Tab / arrow keys).
  2. Switch to Table layout via the Layout button.
  3. Verify the "Post Types" column is reachable and readable via screen reader / keyboard navigation.
  4. Column values should be announced correctly (comma-separated post type names, or "—" for empty).

Screenshots

Table View

image

Grid View

image

List View

image image

@github-actions github-actions Bot added the [Package] Edit Site /packages/edit-site label Feb 27, 2026
Add `post_types` field to the templates REST API schema and response. The field returns an array of post type slugs that can use the template, based on the `postTypes` property defined in theme.json.

- Add `post_types` property to REST API schema for templates and static templates controllers
- Populate `post_types` field in template responses from template file data
- Add Post Types column to templates table view in Site Editor
- Include post_types in default
This reverts commit 290bf9c.

Remove `post_types` field from templates REST API schema and template building logic. This removes the `post_types` property from the static templates controller schema and stops populating the field when building template objects from files.
@Mayank-Tripathi32 Mayank-Tripathi32 force-pushed the add/template-post-types-column branch from 84bb886 to 6b5b019 Compare February 27, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Edit Site /packages/edit-site

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Templates / DataViews: Show declared post types for templates

1 participant