Skip to content

Commit

Permalink
Docs: Indicate custom-fields support is required for registering meta (
Browse files Browse the repository at this point in the history
…#24325)

* register_post_meta requires custom-fields support

Post type needs to support `custom-fields` for `register_post_meta` to work.

* Metabox: register_post_meta requires custom-fields
  • Loading branch information
shramee authored Aug 10, 2020
1 parent 0259002 commit 30ee51f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ register_post_meta( 'post', '_myguten_protected_key', array(
}
) );
```
**Note:** Your post type needs to support `custom-fields` for `register_post_meta` function to work.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ wp.data.select( 'core/editor' ).getCurrentPost().meta;
```

Before adding the `register_post_meta` function to the plugin, this code returns a void array, because WordPress hasn't been told to load any meta field yet. After registering the field, the same code will return an object containing the registered meta field you registered.

If the code returns `undefined` make sure your post type supports `custom-fields`. Either when [registering the post](https://developer.wordpress.org/reference/functions/register_post_type/#supports) or with [add_post_type_support function](https://developer.wordpress.org/reference/functions/add_post_type_support/).

0 comments on commit 30ee51f

Please sign in to comment.