Opened 6 months ago
Last modified 2 months ago
#61308 assigned enhancement
Return `post_types` field in templates REST API
Reported by: | oandregal | Owned by: | oandregal |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
While working on the site editor templates screen, I realized we don't expose the post_types
field through the templates endpoint https://developer.wordpress.org/rest-api/reference/wp_templates/, though it's one of the parameters consumers can use to query it.
In the dataviews-powered page, we want to expose this information so the user can filter templates that are intended to work with a given post type.
My suggestion is to expose this new field through the existing templates REST API endpoint.
Change History (10)
This ticket was mentioned in PR #6660 on WordPress/wordpress-develop by @oandregal.
6 months ago
#1
- Keywords has-patch added
#4
@
6 months ago
- Keywords needs-unit-tests added
- Milestone changed from 6.6 to 6.7
We have 3 hours until the commit freeze before Beta 1 release and no Unit tests. I am rescheduling it to the next milestone. Let's make it when Trunk will be open for enhancements again, without waiting for the last moment. Thank you 😅
This ticket was mentioned in Slack in #core by chaion07. View the logs.
3 months ago
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
3 months ago
#7
@
2 months ago
- Milestone changed from 6.7 to Future Release
The first beta is due in under 20 hours so I'll move this off the milestone as there hasn't been any progress during the release cycle.
This ticket was mentioned in PR #7530 on WordPress/wordpress-develop by @debarghyabanerjee.
2 months ago
#8
Trac Ticket: Core-61308
## Overview
This pull request adds a new post_types
field to the existing WordPress REST API endpoint for templates (/wp/v2/templates
). This enhancement allows users to filter templates based on the post types they are intended for, thereby improving usability and functionality in the site editor templates screen.
## Changes Made
### Modified get_item_schema()
:
- Added a new property, post_types, to the JSON schema for templates.
- The post_types field is defined as an array of strings, describing the associated post types for each template.
### Updated prepare_item_for_response()
:
- Implemented logic to fetch and include the post_types information in the API response.
- Ensured that the post_types field is populated based on the associated post types stored in the template's metadata.
## Benefits
Improved Filtering
: Users can now filter templates directly by their associated post types, making it easier to find relevant templates for specific content types.
Enhanced API Usability
: By exposing the post_types field, we align the API capabilities with user expectations and common use cases.
@martin.krcho commented on PR #7530:
2 months ago
#9
Changes look good. @Debarghya-Banerjee Would you be able to extend the existing unit tests?
@debarghyabanerjee commented on PR #7530:
2 months ago
#10
Hi @martinkrcho , I have fixed the failing test cases. Can you please check it. Thanks.
@spacedmonkey can you, please, take a look. I have doubts that we will be able to make in into 6.6, but it looks simple enough and quite reasonable to have. Thank you!