Replace the Post Excerpt Meta Box with a Field in My Custom Meta Box
Question
I've got a custom meta box for a custom post type which will be the only metabox I plan to show in the main column (except the native title box). I want to move the native Expert box/field inside my Custom Meta Box.
I'm able to create a field called Excerpt in my Meta Box, however I only know how to save this to the Custom Fields, not the original location that the native Except saves to.
Solution
Just name the field 'excerpt'.
E.g.:
<textarea name="excerpt" id="excerpt"><?php echo esc_html( '$post->post_excerpt' ); ?></textarea> <!-- if it is a textarea field -->
or
<input name="excerpt" id="excerpt" value="<?php echo esc_attr( '$post->post_excerpt' ); ?>" /> <!-- if it is a text field -->
OTHER TIPS
This would be a function to update the post_excerpt with a field with the name 'my_custom_field'.
function my_custom_save_function($post_id){
update_post(array('ID' => $post_id, 'post_excerpt' => $_POST['my_custom_field']));
}
add_action('save_post', 'my_custom_save_function');
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange