I've just created a metabox for some custom text on a website I'm developing.
However when I input something into it and click update it doesn't seem to save it. Also its not saving on the MYSQL DB either.
here is the code for my metabox below.
<?php
add_action( 'add_meta_boxes', 'dd_hctb_create' );
function dd_hctb_create() {
add_meta_box ( 'dd_meta', 'Heading Content Text Box', 'dd_hctb_function', 'page', 'normal', 'high' );
}
function dd_hctb_function( $post ) {
echo '<input type="hidden" name="dd_mbe_content_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
//retrieve the metadata values if they exist
$dd_mbe_content = get_post_meta( $post->ID, 'dd_mbe_content', true );
echo 'Write any content in here that you want to appear above the main text.';
echo '<textarea name="middle" id="dd_mbe_content" value="" cols="100%" rows="10">'.$dd_mbe_content.'</textarea>';
}
function dd_hctb_save($post_id) {
//attempt to verify nonce
if (!wp_verify_nonce($_POST['dd_mbe_content_nonce'], basename(__FILE__)))
return $post_id;
// check the autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
//finally verify the postmeta is set
if (isset ( $_POST['dd_mbe_content'] ) ) {
//now save if if the data exists
update_post_meta( $post_id, 'dd_mbe_content', strip_tags( $_POST['dd_mbe_content']));
}
} // end save function
add_action('save_post', 'dd_hctb_save' );
?>
thanks for any help guys - I'm sure this is a typo somewhere or something overriding a setting. I'm new to using wp_nonce aswell so any help or advice is taken on board.