register_post_type & ‘register_meta_box_cb’ argument

I love answering my own questions: Wrap the function add_additional_input_field() in a new function that contains this and call it in the register_meta_box_cb argument.

And yes: This is the solution.

Example:

<?
/** Plugin Name: (WPSE) #6345 Example MetaBox plugin */
add_filter( 'plugins_loaded', function() {
    register_post_type( 'book', [
        'register_meta_box_cb' => function() {
            printf(
                '<label>Length:</label>'
                .'<input name="book-length" value="%s" />',
                get_post_custom( get_the_ID() )['book-length'][0]
            );
        },
        # Other arguments
    ] );
}

Leave a Comment