WP Rest API – How to get featured image


I’m very new to this API, in fact I’ve only spent couple hours on it so far. I’ve done my research but cannot find anything about it…

The issue is, I can’t seem to get the featured image of a post. The JSON returns "featured_media: 0".

getPosts: function() {
  var burl = "http://www.example.com/wp-json/wp/v2/posts";
  var dataDiv = document.getElementById('cards');
    url: burl,
    data: data,
    type: 'GET',
    async: false,
    processData: false,
    beforeSend: function (xhr) {
      if (xhr && xhr.overrideMimeType) {
    dataType: 'json',
    success: function (data) {
      //question: data->featured_image: 0?!
      var theUl = document.getElementById('cards');
      for (var key in data) {
        //doing my stuff here
    error: function(e) {
      console.log('Error: '+e);

I have definitely, set a featured image on the post but data returns:

featured media?

Any help will be appreciated.

, , , Abdul Sadik Yalcin 3 years 2020-05-29T02:12:09-05:00 0 Answers 83 views 0

Leave an answer