Opened 7 years ago
Closed 6 years ago
#44748 closed feature request (invalid)
Ability to register custom embeds to built-in endpoints
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | needs-patch |
Focuses: | rest-api | Cc: |
Description
Couldn't find any tickets related to this, probably because this page is broken (?): https://core.trac.wordpress.org/component/REST+API
There are situations where we "link" to other posts using custom fields, and would like to include said posts when querying for the post that includes said links.
Here's what I already get from the standard /wp/v2/posts/123 endpoint.
"linkedProductCards": [ 856628 ]
I'd like to be able to easily fetch and embed the posts under linkedProductCards, with just one network request.
"_embedded": { "linkedProductCards": [ { "id": 856642, "date": "2018-08-06T14:32:06", .. }, ] }
And I'd like to be able to have control over whether the embedded post also embeds, as making a separate network request to get the featured image object kinda defeats the purpose of this feature.
Change History (5)
#2
@
7 years ago
Hi k1sul1,
This is supported. You can see some more information about it in the [docs](https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/#adding-links-to-the-api-response).
You’ll probably want to use [rest_prepare_post
filter](https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1617) as well.
Nested embeds are not currently supported.
#3
@
7 years ago
Interesting. Didn't read well enough.
So if I understood correctly, I'm to use the rest_prepare_post filter to mutate the response with the add_link call. I think I'll manage.
Will nested embeds ever be supported?
#5
@
6 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Sorry for the late reply @k1sul1!
So if I understood correctly, I'm to use the rest_prepare_post filter to mutate the response with the add_link call. I think I'll manage.
Yep!
Will nested embeds ever be supported?
I'm not sure, see https://core.trac.wordpress.org/ticket/39696#comment:25. I don't think it is on a short term roadmap if that helps any.
This is one way of doing it at the moment but it doesn't feel right.