为了简短起见:我构建了一个包含3个字段的元框,但它只保存了第一个字段。我能做错什么?
// --- 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;
}
这就是我现在所拥有的。它保存了第一个字段(career_subtitle),但没有保存其他2个字段。解决这个问题非常重要,所以我非常感谢一个有效的答案:)
答案 0 :(得分:4)
这可能不是您问题的解决方案,但您确定textarea具有值属性????
这可以解决您的问题: -
<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>