javascript – Autosave metabox fields in WordPress Gutenberg autosave

Question

I want to auto save values entered in metabox in Gutenberg editor. Gutenberg by default does not store the values entered in metabox while it auto saves. I tried this code but it’s not working. Please help.

wp.data.subscribe(function () {

const wasAutosavingPost = select('core/editor').isAutosavingPost();
if (wasAutosavingPost) {
if (select('core')._experimentalGetDirtyEntityRecords().length > 0) {
const intervalId = setInterval(() => {
if (select('core/editor').isAutosavingPost() === false) {
dispatch('core/editor').savePost();
clearInterval(intervalId);
}
}, 100);
}
}

});

0
Ryan Tan 3 months 2022-05-30T00:27:10-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse