do_action( ‘block_editor_meta_box_hidden_fields’, WP_Post $post )

Adds hidden input fields to the meta box save form.

Description

Hook into this action to print <input type="hidden" ... /> fields, which will be POSTed back to the server when meta boxes are saved.

Parameters

$postWP_Post
The post that is being edited.

Source

do_action( 'block_editor_meta_box_hidden_fields', $post );

Changelog

VersionDescription
5.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    In save_post hook, to check if the post is published via gutenberg, use this

    add_action( 'block_editor_meta_box_hidden_fields', 'add_gutenberg_hidden_fields', 10, 1 );
    function add_gutenberg_hidden_fields( $post ) {
    
    	echo '<input type="hidden" name="your-field" value="some-value">';
    	echo '<input type="hidden" name="is_gutenberg_post" value="1">';
    }

    then inside save_post callback, use

    if ( isset( $_POST['is_gutenberg_post'] ) ) {
        // came from gutengerg
    }

You must log in before being able to contribute a note or feedback.