wp-rest-api-cache
                                
                                 wp-rest-api-cache copied to clipboard
                                
                                    wp-rest-api-cache copied to clipboard
                            
                            
                            
                        Embedded Media is not cached properly
I am embedding related media in my requests for a custom post type. When I get a cached response, the media array (post._embedded['wp:featuredmedia']) contains a copy of the array of posts I just received ( minus the _embedded property on each of the elements ).
I am having the same issue
Hi,
I can't simulate this error, as I reported it here: https://wordpress.org/support/topic/not-working-with-_embed/#post-8808911
Can someone send me the files used with a dump of the database? [email protected]
Thanks
This may help. I am having the same problem and was able to duplicate it on this site here https://wp-api.webhostingforstudents.com with the following data.
It looks like instead of getting the correct embedded content (media or author) it is getting post data instead.
Without plugin:

With plugin:

I'm encountering this issue too.
@airesvsg - in your video, the bug reported here is visible at 4:53, where you select the data inside the author field. Correct me if I'm wrong, but I think this is exactly the behaviour as described in this bug.
I think I'm having the same issue, the non-cached response contains everything we need but the cached version is coming back different. We're relying on the _embed response containing "media_details" which lists all of the images sizes and paths to the images.
The non-cached response of one of our requests contains just 2000 lines or so of JSON, whereas the exact same request when cached comes back with 50,000+ lines of JSON which means the cached response actually takes 1.5 seconds longer than the non-cached version, all the nesting looks different and no longer contains "media_details" within the "wp:featuredmedia" block so our images stop working.
 
                                    
                                    
                                    
                                
I can verify we are also having the same issue.
@airesvsg Any update on this? Would a database dump help?
I'm having this issue using Angular as a front end.
After caching I lose the author object/name and just get an id: post._embedded.author[0].name <-- missing
And my featured media is a list of posts instead of the media data.
Hope this is fixable, will be a useful plugin!
Thanks
withcache.txt withoutcache.txt
Exact same issue. This is an absolute blocker for me. Not having featured images is terrible.
I can confirm,, ?_embed doesn't work, the embed object
"_embedded": { ... }
gets omitted from the json
having this issue as well :(
Ok so here is how i got around it. So far seems to work. I installed the plugin : https://wordpress.org/plugins/better-rest-api-featured-images/
and simply ignored the _embed.
@harrisrobin's response above worked for me. Had the same issue but this was a viable workaround.
I'll rewrite my plugin in the next month and I'll fix it.
Thanks
I´m currently testing to cache the full outgoing result in the rest_pre_echo_response hook and apply the cache in the rest_pre_dispatch hook.  Seems to work. I also need to reset the $_GET['_embed'] = null; after applying the cache to the result to stop the embedded links to be dispatched since the embedded result is in the cached result already. If you like the solution I can make a PR. Sorry for my incorrect old reply, I deleted that one.
Any update on this fix? Still able to replicate the issue.
@ahrberg Could you show your code?
There is any solutions to this bug yet?