diff --git a/packages/edit-post/src/store/actions.js b/packages/edit-post/src/store/actions.js index 8dd473dd9a33f..d00f7472382f8 100644 --- a/packages/edit-post/src/store/actions.js +++ b/packages/edit-post/src/store/actions.js @@ -9,6 +9,7 @@ import { } from '@wordpress/editor'; import deprecated from '@wordpress/deprecated'; import { addFilter } from '@wordpress/hooks'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -289,9 +290,21 @@ export const requestMetaBoxUpdates = window.tinyMCE.triggerSave(); } + // We gather the base form data. + const baseFormData = new window.FormData( + document.querySelector( '.metabox-base-form' ) + ); + + const postId = baseFormData.get( 'post_ID' ); + const postType = baseFormData.get( 'post_type' ); + // Additional data needed for backward compatibility. // If we do not provide this data, the post will be overridden with the default values. - const post = registry.select( editorStore ).getCurrentPost(); + // We cannot rely on getCurrentPost because right now on the editor we may be editing a pattern or a template. + // We need to retrieve the post that the base form data is referring to. + const post = registry + .select( coreStore ) + .getEditedEntityRecord( 'postType', postType, postId ); const additionalData = [ post.comment_status ? [ 'comment_status', post.comment_status ] @@ -301,10 +314,7 @@ export const requestMetaBoxUpdates = post.author ? [ 'post_author', post.author ] : false, ].filter( Boolean ); - // We gather all the metaboxes locations data and the base form data. - const baseFormData = new window.FormData( - document.querySelector( '.metabox-base-form' ) - ); + // We gather all the metaboxes locations. const activeMetaBoxLocations = select.getActiveMetaBoxLocations(); const formDataToMerge = [ baseFormData,