Gutenberg: Meta is not saved to preview

Created on 31 Oct 2018  路  9Comments  路  Source: WordPress/gutenberg

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:

  1. Install ACF or any similar plugin.
  2. Create a basic text field "test" for the page or post edit screen.
  3. Fill in a value for this field and publish the post.
  4. Edit the "single.php" template file to output this "test" meta (for visual reference)
  5. Note that when viewing the post, you can see this meta data output into the HTML
  6. Edit the post again and modify the field value
  7. Click preview
  8. Note that the "test" meta has not changed on the front-end. Also, the revision created in the DB does not contain any postmeta data.

Expected behavior
When viewing a preview (step 8), the "test" meta should reflect its updated value.

Additional context

  • WordPress version 4.9.8
  • Gutenberg plugin version 4.1.1
REST API Interaction [Feature] Meta Boxes [Feature] Saving [Priority] High [Status] In Progress [Type] Bug

Most helpful comment

Still experiencing the issue with WP Version 5.2.2 and ACF Pro 5.8.3

All 9 comments

Related to #9151

I was able to verify this issue:

metavalue

Notably:

  1. If you change the value of your test meta box and hit "Preview", the change is not saved to the database and the Preview includes the old value.
  2. If you change the value of your test meta box and hit "Save Draft", then the change _is_ saved to the database and the Preview includes the new value.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidsword picture davidsword  路  3Comments

moorscode picture moorscode  路  3Comments

aaronjorbin picture aaronjorbin  路  3Comments

mhenrylucero picture mhenrylucero  路  3Comments

JohnPixle picture JohnPixle  路  3Comments