Describe the bug
When previewing a post in Gutenberg, meta is not saved from metaboxes.
When previewing a post in the "classic editor", the form would submit and trigger the "save_post" action for the "revision" allowing plugins such as ACF to save postmeta from the $_POST data.
I assume that the "save_post" action is being fired correctly, but the metabox data is not available in $_POST. This results in no metadata saved for the preview.
Metadata should not be ignored from the "preview". Many agencies use custom fields to allow clients to edit bespoke websites who use preview in their workflow.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
When viewing a preview (step 8), the "test" meta should reflect its updated value.
Additional context
Related to #9151
I was able to verify this issue:
Notably:
For published post, there's similar behavior: the change isn't included in the Preview until the "Update" button is clicked.
Also, for the next person, here's my test code for the meta box:
add_action( 'add_meta_boxes', function(){
add_meta_box( 'test', 'Test', function(){
echo '<input name="daniel_test" value="' . get_post_meta( get_the_ID(), 'daniel_test', true ) . '" />';
});
});
add_action( 'save_post', function( $post_id ){
if ( ! isset( $_POST['daniel_test'] ) ) {
return;
}
update_post_meta( get_the_ID(), 'daniel_test', $_POST['daniel_test'] );
});
add_filter( 'the_content', function( $content ){
$content .= 'Daniel test: ' . get_post_meta( get_the_ID(), 'daniel_test', true );
return $content;
});
Worth noting that fixing this by saving meta will introduce a longstanding core bug: https://core.trac.wordpress.org/ticket/20299 - that is: because meta is not revisioned, we may need to update the actual post meta for previewing.
Worth noting that fixing this by saving meta will introduce a longstanding core bug:
Correct. Because this is a known existing issue, it's safe to reintroduce.
Per #core-restapi
conversation today, @adamsilverstein will work on this later this afternoon.
It should be fixed with #11409.
Still experiencing the issue with WP Version 5.2.2 and ACF Pro 5.8.3
I can confirm that the issue is still here in WP 5.4.2
Most helpful comment
Still experiencing the issue with WP Version 5.2.2 and ACF Pro 5.8.3