Skip to content
Guides

Custom Post Type and Save in Meta control

When implementing blocks with the Save in Meta option in Custom Post Types, it's crucial to ensure your post type properly supports custom fields. This guide explains how to set up Custom Post Types correctly for use with Lazy Blocks meta fields.

Registering Custom Post Type

Here's how to register a Custom Post Type with proper support for both the block editor and meta fields:

PHP
function create_my_custom_post_type() {
    register_post_type(
        'my_custom_post',
        array(
            'labels' => array(
                'name'          => __('My Custom Post'),
                'singular_name' => __('My Custom Post')
            ),
            'public' => true,
 
            // Enable Gutenberg editor support
            'show_in_rest' => true,
 
            'supports' => array(
                'title',
                'editor',
                'thumbnail',
                // Enable custom meta fields support
                'custom-fields',
            ),
        )
    );
}
add_action('init', 'create_my_custom_post_type');

Important Considerations

  • Always include show_in_rest => true to ensure compatibility with the block editor
  • Add custom-fields to the supports array to enable meta field functionality
  • Register your Custom Post Type early in the WordPress initialization process using the init hook

Without proper custom-fields support, blocks with the "Save in Meta" option will not function correctly in your Custom Post Type.

This setup ensures your Custom Post Type works seamlessly with Lazy Blocks' meta field features while maintaining full compatibility with the WordPress block editor.

Was this article helpful?