If you call the REST API using _embed parameter you will be able to get the embedded objects as "_embedded" JSON object of returned JSON as following:
/?rest_route=/wp/v2/posts&_embed
And if you use _fields parameter you can filter out the objects returned by API like:
/?rest_route=/wp/v2/posts&_fields=id,content,title
The problem is when both are_embed and _filter are used simultaneously the results returned do not contain "_embedded" JSON object no matter what combination of filter I apply. For example:
/?rest_route=/wp/v2/posts&_embed&_fields=id,content,title,_embedded
does not return "_embedded" JSON object
Worpress Version is 5.3.2 (Latest)
And pretty permalinks are not enabled so usage of "/?rest_route=" is mandatory
As answered previously, it would seem the _link is necessary to figure out how to get the _embed property. But if you're like me and want to really minimize the amount of JSON that is returned, you can do the following.
Suppose you want the wp:featuredmedia property of _embedded. Then you can request
OPTION 1
/wp/v2/pages?_embed=wp:featuredmedia&_fields=_links.wp:featuredmedia,_embedded
_embed => wp:featuredmedia
_fields => _embedded and _links.wp:featuredmedia (so that embedding will actually work)
OPTION 2: A slight variation that also works
/wp/v2/pages?_embed&_fields=_links.wp:featuredmedia,_embedded.wp:featuredmedia
_embed => tells us to do embedding
_fields => _links.wp:featuredmedia,_embedded.wp:featuredmedia (ensures we only return those)
You need to add _links to get the JSON object:
/wp-json/wp/v2/posts?_fields=id,content,title,_links,_embedded&_embed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With