Add New Custom Field Upon Post Creation

Looking to add a new custom field upon post creation? All you may need is to call add_post_meta() when inserting a new post.

Adding new post meta upon post creation

To add a new post meta field upon post creation, you need to add the code below to your WordPress theme’s functions.php file.

function add_new_custom_field( $post_id ) {
     add_post_meta( $post_id, 'new_custom_field_name', 'Default Value' );
add_action( 'wp_insert_post', 'add_new_custom_field' );

Note, if this is a unique value; add the $unique value of true to the end of add_post_meta().