Invalidate getEntityRecords Cache in the WordPress Block Editor (Gutenberg)

Matt Watson's photo
Matt Watson
·Jul 28, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

If you have used the Gutenberg API to include post data in your blocks, say with getEntityRecords, and you have some level of interactivity that changes the block, you may find that the block will not update do to the cache.

To clear the cache use this technique:

wp.data.dispatch( 'core' ).receiveEntityRecords( 'postType', 'post', [], {}, true );

The fifth parameter will ensure the cache is invalidated, and the calls getEntityRecords within your block will be reloaded.

 
Share this

Impressum

© Wholesome Code Ltd. (Business No: 12196107) All rights reserved.