Meta box only saving the first of multiple input fields

To keep it short: I built a meta box with 3 fields, but it’s only saving the first field. What could I be doing wrong?

// --- METABOX: CAREER ... CONTENTS --- //
function career_meta(){
global $post;
$career1 = get_post_meta( $post->ID, 'career1', true );
$career2 = get_post_meta( $post->ID, 'career2', true );
$career3 = get_post_meta( $post->ID, 'career3', true );
?>
<label for="career_subtitle">Subtitle</label><input type="text" class="widefat" id="career-subtitle" name="career_subtitle" value="<?php echo $career1; ?>" />
<label for="career_text_1">Left Column</label><textarea class="widefat" id="career-text-1" name="career_text_1" value="<?php echo $career2; ?>"></textarea>
<label for="career_text_2">Right Column</label><textarea class="widefat" id="career-text-2" name="career_text_2" value="<?php echo $career3; ?>"></textarea>
<?php }

// --- METABOX: CAREER ... SAVE --- //
add_action('save_post', 'save_career');
function save_career(){
    global $post;
    update_post_meta($post->ID, "career1", $_POST["career_subtitle"]);
    update_post_meta($post->ID, "career2", $_POST["career_text_1"]);
    update_post_meta($post->ID, "career3", $_POST["career_text_2"]);
}
add_action('save_post','function_save_var');
function function_save_var()
{
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
    return $post_id;

}

That’s what I have right now. It saves the first field (career_subtitle) but not the 2 other ones. Fixing this is quite important so I would really appreciate an effective answer 🙂

Related posts

Leave a Reply

1 comment

  1. This maynot be the solution to your question but are you sure that textarea has a value attribute????

    This could solve your problem:-

    <label for="career_text_1">Left Column</label><textarea class="widefat" id="career-text-1" name="career_text_1"><?php echo $career2; ?></textarea>
    <label for="career_text_2">Right Column</label><textarea class="widefat" id="career-text-2" name="career_text_2"><?php echo $career3; ?></textarea>