Ollie Block Academy

Dealing with Post Meta

Making Post Meta Accessible the Block Editor

Register post meta using register_post_meta() with essential parameters: post type, meta key, data type, single/multiple values, sanitization callback, and show_in_rest configuration.

Set show_in_rest to true for block editor access, but ensure custom post types support custom-fields or meta won’t appear. Use appropriate sanitization callbacks like sanitize_text_field for security.

Once registered, meta fields appear in REST API endpoints and become accessible through getEditedPostAttribute('meta') in blocks. Always register meta in PHP before attempting JavaScript access.

Back to: Ollie Block Academy > Dealing with Post Meta