API Loop - Featured Image

Hi,

This might be a feature request or a bug because it seems like it should work.

I have a main site and a shop site and I want to list news from the main site on the shop site and products from the shop on the main site. I want to make the sites seem seamless.

However, the API request for posts and product do not include the featured media. They have a reference to the media ID. So, I thought it would be as simple as creating another API call to the media endpoint and pass the image ID. I used the bricks tag for the output ID and attempt to append it to the API URL like so: [site_url]/wp-json/wp/v2/media/{query_api @key:‘featured_media’}. This didn’t work, so I tried create a tag with the first loop to output the media ID: {query_api @key:‘featured_media’}. That didn’t work either. Then I tried to pass on the ID of the first loop to grab the media by partent= … same.

So despite there being icons for adding dynamic content in the API builder fields, I’m guessing the API query doesn’t accept dynamic data? This assumption is strentthed because when I append the dynamic tag to the URL it then returns a 404 error.

I could get away with news on the shop not having an image, but showing products need a relevant image.

Thanks for any solutions or pointing out something obvious I might (probably) have missed.

-Ron

I just noticed that I pasted the API key in place of the created dynamic key, which really doesn’t make a difference, but I created it as {api_product_image}.

-Ron

Hi @Ron ,

You can add _embed=true so the featured image will be returned under _embedded key as well.

Example:

Regards,
Jenn

Hi Jenn,

Thank you for clarifying the _embed. I did come across the documentation for that variable in the WP API, but I didn’t have the value set to TRUE. So thank you.

Though, I think it would be a good upgrade to be able to nest API calls. Say for wanting to get all the media associate with a post. Or if the API you were connecting to had separate endpoints associated by an ID or key.

But for my needs this is perfect. Maybe… does the API include custom fields?

-Ron