Skip to content

Cant update existing post meta if Custom Field Meta Box open #48926

Closed as not planned
@gin0115

Description

@gin0115

Description

Following the example found here https://developer.wordpress.org/block-editor/how-to-guides/metabox/ there is an issue updating meta, if the Custom Fields Panel is open.

It looks like there is a race condition happening where the meta field is updated via the block, but then the custom fields below are updated afterwards using the static values below.

This can be negated by either

  • Ensuring the custom field panel is always closed
  • Prefixin the meta key with an _
  • Using the is_protected_meta filter to mark the field as protected

The last 2 options just suppresses the field from being shown in the Custom Fields Panel.

Not sure what can be done about this, but ideally should be documented on the above developer guide, as this confused me.

Step-by-step reproduction instructions

Create the block as detailed here
Turn on the custom field Panel
Set a value using the block and reload the page, your meta should be set (and displayed)
Update the meta field and reload the page once saved, it will be reverted back to the initial value (as the custom fields below do not get updated)

Screenshots, screen recording, code snippet

metabox.issue.mp4

Environment info

WP 6.1.1
No plugins active bar the one with this block.
Twenty Twenty Two theme or Twenty Twenty One or Twenty Twenty
Chrome and Firefox on Ubuntu

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Meta BoxesA draggable box shown on the post editing screen[Status] DuplicateUsed to indicate that a current issue matches an existing one and can be closed[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions