I am trying to get the input from a textbox and display it upon update.
I don't know if the update_post_meta
or get_post_meta
is causing the problem.
Code
//Metabox Hook
add_action('add_meta_boxes','stars_meta_box');
//Metabox Init
function stars_meta_box(){
global $post;
add_meta_box('first_name_meta_box',
'First Name','first_name_meta_box_html','spark_stars','normal','default');
}
//Metabox Html
function first_name_meta_box_html(){
wp_nonce_field('first_name','first_name_meta_box_nonce');
$value = get_post_meta( $post->ID, 'first_name_meta_box_key', true ); ?>
<label>First Name: </label> <input type="text" name="fname" value="<?php echo $value; ?>"/>
<?php }
//Save Hook
add_action( 'save_post', 'save_meta_box' );
//Save Metabox Value
function save_meta_box(){
global $post;
update_post_meta( $post->ID, "first_name_meta_box_key", $_POST["fname"]);
}
The problem is that when I type a value in the textbox and update the page, the textbox remains blank.