I want to use the REST API of wordpress to build a new version of a custom theme. I'm able to get the json response of a particular category, but I need to find a way to obtain also the featured image or the second post thumbnail registered using a plugin, so I can use them in the layout. Is this possible without using a plugin?

here is the code I'm using for testing:


    $.getJSON('https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolio&per_page=50&_embed', function(response){
      $.each(response, function(i){


the last part of the console log will not work but the [0].source_url is the info I need for each JSON post provided.

  • You'll need to add that field in to the REST API response, but keep in mind that you should probably raise this as a feature request for that plugin via their support mechanism. If there was a plugin that would do this, it would be the plugin you're using, or from the same vendor. I think the best you can hope for is how to add fields to the response the REST API gives, or add a piece of post meta to it, otherwise the specifics of this specific plugin you're using require speciailist knowledge of that plugin which would be offtopic on this site – Tom J Nowell Nov 12 at 19:06
  • I'm not using a plugin, I wrote my own if needed or use the native CMS functions. I want only to use the source_url to obtain the url from the response, it will give me an undefined error for now i chrome console. – sialfa Nov 12 at 19:17
  • hmm if the source_url doesn't work, how did you come upon it to begin with? Note that the the second post thumbnail registered using a plugin, part can't be answered at the moment as there's zero information about the plugin you wrote and how it stores information – Tom J Nowell Nov 12 at 19:57
  • ´source_url´ is a parameter that will be returned from the API key when the _embed querystring param is used. For the second plugin is the famous Multiple post thumbnail, but I don't have a link to it – sialfa Nov 12 at 21:52
  • 1
    solved!thank you – sialfa Nov 14 at 5:21

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.