So i created a custom meta box, here is the code :
add_action( 'add_meta_boxes', 'register_meta_box' );
function register_meta_box(){
add_meta_box( 'author_email', 'Author Email Id', 'meta_author_email', 'post', 'side', 'default' );
}
function meta_author_email($post){
wp_nonce_field( 'author_save_email_data', 'email_meta_box_nonce' );
$value = get_post_meta( $post->ID, '_author_email_value_key', true );
echo '<label for="author_email_field">Author Email Address: </label>';
echo '<input type="email" id="author_email_field" name="author_email_field" value="'. esc_attr( $value ) .'" size="25"/>';
}
function author_save_email_data($post_id){
if (!isset($_POST['email_meta_box_nonce'])) {
return;
}
if (!wp_verify_nonce( $_POST['email_meta_box_nonce'], author_save_email_data )) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can( 'edit_post', $post_id )) {
return;
}
if (!isset($_POST['author_email_field'])) {
return;
}
$mydata = sanitize_text_field( $_POST['author_email_field'] );
update_post_meta( $post_id, '_author_email_value_key', $mydata );
}
add_action( 'save_post', 'author_save_email_data' );
This is how i am calling it on my single page
<?php echo get_post_meta( get_the_ID(), 'author_email_field', true ); ?>