Gutenberg: Cannot save to meta from block in custom post type

Created on 16 May 2018  Â·  4Comments  Â·  Source: WordPress/gutenberg

The issue

When a block saves one of its attributes to a custom meta field, that block does not work in custom post types, as the value you input will be erased on save.

Reproduction steps

  1. Create a plugin that registers a custom meta field and a custom block.
  2. Give the custom block an attribute that is sourced from the custom meta field.
  3. Add an input field to the custom block to change the value of the meta field.
  4. Install the plugin on a WordPress site with Gutenberg installed.
  5. Create a new standard core WordPress post.
  6. Insert the custom block and input some data to be saved to the custom meta field.
  7. Notice that the data is retained upon save.
  8. Create a new post of your custom post type.
  9. Insert the custom block and input some data to be saved to the custom meta field.
  10. Notice that the data is removed upon save.

Expected behavior

You should be able to save attributes to a custom meta field in a custom block in any post type, not just the core ones.

Most helpful comment

Does the custom post type has defined support for custom-fields?

All 4 comments

Does the custom post type has defined support for custom-fields?

@ocean90 I just tested, and adding support for custom-fields to my custom post type fixed the issue. However, that should not be necessary, as my custom meta field was explicitly registered via register_meta and is not a user-created field… right? Do I just misunderstand the meaning of custom-fields support?

I guess I was mistaken then. Thanks for pointing that out, @ocean90! :smile:

Closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidsword picture davidsword  Â·  3Comments

spocke picture spocke  Â·  3Comments

moorscode picture moorscode  Â·  3Comments

maddisondesigns picture maddisondesigns  Â·  3Comments

franz-josef-kaiser picture franz-josef-kaiser  Â·  3Comments