Support General Set default value to field if this value still not exist Reply To: Set default value to field if this value still not exist

#13053
Anh TranAnh Tran
Keymaster

Hi Jefferson,

You can use std attribute for a text field, like this:

$post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : ( isset( $_POST['post_ID'] ) : intval( $_POST['post_ID'] ) : false );
$meta_boxes[] = [
    'fields' => [
        [
            'type' => 'text',
            'id' => 'color',
            'std' => generate_my_own_code( $post_id ),
        ],
    ],
];