WP REST Cache conflicts with getEntityRecords() calls for ‘attachme
-
I have been making use of getEntityRecords() to fetch image data to display in some custom Gutenberg blocks. They worked fine until I upgraded to WordPress 5.6. However, I can successfully fetch image data by using getMedia(). This was the behavior I experienced on my live and staging sites. I deactivated all plugins and re-activated them one by one and determined that WP REST Cache was causing the conflict.
Steps to reproduce the behavior:
- Make a clean WordPress installation
- Upload an image to the media library and take note of it’s post_id (let’s say it’s 6)
- Open the page editor and the Javascript console then type in
wp.data.select('core').getEntityRecords('postType', 'attachment', { include: [ 6 ] })
- You’ll see
null
returned, which is normal since the image is still being fetched, but repeating the getEntityRecords call after a few seconds should return an array with the media item details - Instead type in wp.data.select(‘core’).getMedia(6) (same as above, you’ll likely get ‘undefined’ the first time while it’s fetching the media item, but if you re-enter you should be able to see the details for that image)
I tried clearing the WP REST cache while testing, thinking that would alleviate any potential conflicts with these getEntityRecords() calls, but clearing the cache had no effect I consistently received null responses on the getEntityRecords calls. Whenever I disable WP REST Cache everything works as expected.
- The topic ‘WP REST Cache conflicts with getEntityRecords() calls for ‘attachme’ is closed to new replies.