Not having access to the functions file, I can't add the function to add the featured image to the API so I need to use wp-json/wp/v2/posts?_embed.
One approach is to cast the objects as arrays. I recently had to do this in a project where I retrieved a list of articles and needed to display the featured image. There may be alternate ways to handle this issue, but I've found it to be reliable. Here is some relevant code from the project.
$post->_embeddedis an object which is an instance of the generic "empty" class in PHP, namely
stdClass. So you should've instead used
$post = json_decode( 'JSON string' )? 🙂 And I actually wondered - why do you need to use
wp_remote_get()if the code runs on the same site where you're making the REST API request to? I mean, can't you just do a
new WP_Queryand get the featured image (URL) using WordPress functions?
wp_remote_getbecause I am loading posts from another website via the API, so I can't use