ClassicPress PetitionsClassicPress Petitions
This is a read-only archive. Post or comment on the live version of this page on our forums.

Add featured +- attached images to post endpoint in REST API

November 27, 2018 · 17:27 · Laurence Bahiirwa

When one pulls up the endpoint "wp-json/wp/v2/posts" we get a key called "featured_media" but it returns an integer value.

Can't we rewrite this to give a proper URL to the featured image? or even add another key that has attached images as URLs.

This will prevent the extra queries one has to return the image URLs or even install bloated plugins to get this information.

I know the endpoint already has so much information one rarely needs thus the growth of tech like GraphQL but we could also consider Author name & description to the individual posts.

This is voice is for decoupling ClassicPress to modern apps or front-ends.

Difficulty: Hard
Request: Add feature
Laurence Bahiirwa

I am doing something for testing here.

James Nylen

I don't think this is necessary. You can use /wp-json/wp/v2/posts?_embed instead.

This returns more information than desired, in your case. Here is a proposed change that will help with this issue in a backwards-compatible way:

James Nylen

In the meantime, this is fairly easy to do in a plugin. Here is some code to use as a starting point:

Laurence Bahiirwa

wp-json/wp/v2/posts?_embed is not always reliable from my experience. Errors are returned thats why I always edit the endpoint with the code shared. It also adds alot of lines of code on endpoint making it slower.