wp-rest-api-cache icon indicating copy to clipboard operation
wp-rest-api-cache copied to clipboard

Embedded Media is not cached properly

Open lejeunerenard opened this issue 8 years ago • 19 comments

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 ).

lejeunerenard avatar Mar 09 '17 06:03 lejeunerenard

I am having the same issue

frankblundt avatar Apr 19 '17 21:04 frankblundt

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

airesvsg avatar Apr 20 '17 00:04 airesvsg

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.

import files

It looks like instead of getting the correct embedded content (media or author) it is getting post data instead.

Without plugin: screen shot 2017-06-26 at 12 12 37 am

With plugin: screen shot 2017-06-26 at 12 13 13 am

zgordon avatar Jun 26 '17 04:06 zgordon

I'm encountering this issue too.

krestaino avatar Aug 03 '17 01:08 krestaino

@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.

bjentsch avatar Aug 15 '17 17:08 bjentsch

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.

screen shot 2017-09-01 at 14 24 47

scottjs avatar Sep 01 '17 13:09 scottjs

I can verify we are also having the same issue.

crankeye avatar Sep 27 '17 23:09 crankeye

@airesvsg Any update on this? Would a database dump help?

krestaino avatar Nov 08 '17 19:11 krestaino

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.

wpbug

Hope this is fixable, will be a useful plugin!

Thanks

mjharper84 avatar Nov 21 '17 12:11 mjharper84

withcache.txt withoutcache.txt

Exact same issue. This is an absolute blocker for me. Not having featured images is terrible.

celandro avatar Dec 03 '17 06:12 celandro

I can confirm,, ?_embed doesn't work, the embed object

"_embedded": { ... }

gets omitted from the json

KSVQ avatar Dec 20 '17 21:12 KSVQ

having this issue as well :(

harrisrobin avatar Feb 14 '18 17:02 harrisrobin

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 avatar Feb 14 '18 18:02 harrisrobin

@harrisrobin's response above worked for me. Had the same issue but this was a viable workaround.

davidgolden avatar Mar 14 '18 20:03 davidgolden

I'll rewrite my plugin in the next month and I'll fix it.

Thanks

airesvsg avatar Mar 14 '18 20:03 airesvsg

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.

ahrberg avatar Aug 11 '18 13:08 ahrberg

Any update on this fix? Still able to replicate the issue.

jmikrut avatar Nov 19 '18 22:11 jmikrut

@ahrberg Could you show your code?

firefiesta avatar Nov 20 '18 11:11 firefiesta

There is any solutions to this bug yet?

jffluis avatar Mar 11 '19 21:03 jffluis