0

I created a custom post type and am getting the posts using the REST API. The returned json looks like this...

categories: [] 
content: {raw: "Morbi mollis tellus ac sapien. Etiam ut purus matt…allis tellus, vitae iaculis lacus elit id tortor.", 
rendered: "<p>Morbi mollis tellus ac sapien. Etiam ut purus m… tellus, vitae iaculis lacus elit id tortor.</p>", 
protected: false, block_version: 0 } 
date: "2018-12-20T17:57:44" 
date_gmt: "2018-12-20T17:57:44" 
featured_media: 189 
generated_slug: "book-post-two"
...

Unlike normal posts, it is not returning featured_image_src. Just featured_media. Is it possible to make the features image source appear in json? How can I get it in js?

  • But it does, featured_media is the attachment ID of the featured image. Use the media endpoint to then fetch information about that attachment via fetch( '/wp-json/wp/v2/media/189)....` – Tom J Nowell Dec 22 '18 at 21:13
  • You can use the global _embed parameter to include the media data in the same API response. And the data is available under the wp:featuredmedia item in the _embedded item of the main response data - Single post; Multiple posts. For CPTs, replace the posts in the URL with the proper rest_base. – Sally CJ Dec 23 '18 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.