1

when I make a request to http://localhost/wordpress/wp-json/wp/v2/posts/?_embed&categories=${categoryId}&per_page=${state.perPage}

I get the following result

[                                                                                                            
  {
    id: 3,
    date: '2019-04-20T16:10:00',
    date_gmt: '2019-04-20T16:10:00',
    guid: {
      rendered: 'http://localhost/wordpress/?p=3'
    },
    modified: '2019-04-20T16:36:30',
    modified_gmt: '2019-04-20T16:36:30',
    slug: 'slug-title',
    status: 'publish',
    type: 'post',
    link: 'http://localhost/wordpress/2019/04/20/slug-title/',
    title: {
      rendered: 'title'
    },
    content: {
      rendered: '\n<figure class="wp-block-image"><img ' +
        'src="http://localhost/wordpress/wp-content/uploads/2019/04/sirius.jpg" ' +
        'alt="" class="wp-image-4" ' +
        'srcset="http://localhost/wordpress/wp-content/uploads/2019/04/sirius.jpg ' +
        '370w, ' +
        'http://localhost/wordpress/wp-content/uploads/2019/04/sirius-217x300.jpg ' +
        '217w" sizes="(max-width: 370px) 100vw, 370px" ' +
        '/></figure>\n',
      protected: false
    },
    excerpt: {
      rendered: '',
      protected: false
    },
    author: 1,
    featured_media: 0,
    comment_status: 'open',
    ping_status: 'open',
    sticky: false,
    template: '',
    format: 'standard',
    meta: [],
    categories: [
      3
    ],
    tags: [],
    _links: {
      self: [Array],
      collection: [Array],
      about: [Array],
      author: [Array],
      replies: [Array],
      'version-history': [Array],
      'predecessor-version': [Array],
      'wp:attachment': [Array],
      'wp:term': [Array],
      curies: [Array]
    },
    _embedded: {
      author: [Array],
      'wp:term': [Array]
    }
  }
]

But as you can see there is no featured_media. Do I have a misunderstanding about featured_media? I made my post with an image like you can see in content.rendered

  • 1
    Well, I don't think the post actually has a featured image. The one in the content.rendered is an image added using the Image block. You set the featured image via the "Set featured image" link in the "Featured Image" meta box, even when using the block editor. – Sally CJ Apr 25 '19 at 16:12
  • 1
    Possible duplicate of WP Rest API - How to get featured image – leymannx Apr 25 '19 at 16:13
  • @evgenifotia, I'm glad the comment helped. And just to be clear, this is what I meant, which is for the block editor. :) – Sally CJ Apr 25 '19 at 16:30
  • 1
    @SallyCJ I have wordpress in french that's why I haven't realized that meta box thank you – evgeni fotia Apr 25 '19 at 16:39

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.