I haven't made any meta-box's in quite some time so quickly threw together this one for a website I'm developing.
My problem is that when I input some text in the box's and hit save the text disappears so I'm left with empty text box's and no saved data.
I'm guessing this is something to do with my save_post
function
updated* Now the title field works but the content one doesn't.
//intialising the metabox and using the callback function
add_action( 'add_meta_boxes', 'owl_mb_create' );
function owl_mb_create() {
add_meta_box( 'owl-meta', ' Inner Page Box', 'owl_mb_function', 'page', 'normal', 'high' );
}
?>
<?php
function owl_mb_function( $post ) {
//retrieve the metadata values if they exist
$owl_mb_content_one = get_post_meta( $post->ID, 'owl_mb_content_one', true);
$owl_mb_title_one = get_post_meta( $post->ID, 'owl_mb_title_one', true);
$owl_mb_content_two = get_post_meta( $post->ID, 'owl_mb_content_two', true);
$owl_mb_title_two = get_post_meta( $post->ID, 'owl_mb_title_two', true);
$owl_mb_content_three = get_post_meta( $post->ID, 'owl_mb_content_three', true);
$owl_mb_title_three = get_post_meta( $post->ID, 'owl_mb_title_three', true);
echo 'Please fill in the forms below';
?>
<p>title:<input type="text" name="owl_mb_title_one" value=" <?php echo esc_attr( $owl_mb_title_one ); ?>" /></p>
<p>content:</p><textarea cols="1" rows="8" name="owl_mb_content_one" id="excerpt"value=" <?php echo esc_attr( $owl_mb_content_one ); ?>"></textarea>
<br />
<p>title:<input type="text" name="owl_mb_title_two" value=" <?php echo esc_attr( $owl_mb_title_two ); ?>" /></p>
<p>content:</p><textarea cols="1" rows="8" name="owl_mb_content_two" id="excerpt"value=" <?php echo esc_attr( $owl_mb_content_two ); ?>"></textarea>
<br />
<p>title:<input type="text" name="owl_mb_title_three" value=" <?php echo esc_attr( $owl_mb_title_three ); ?>" /></p>
<p>content:</p><textarea cols="1" rows="8" name="owl_mb_content_three" id="excerpt"value=" <?php echo esc_attr( $owl_mb_content_three ); ?>"></textarea>
<?php } ?>
<?php
//hook to the save the meta box data
add_action( 'save_post', 'owl_mb_save_meta' );
function owl_mb_save_meta ( $post_id ) {
//save the metadata
update_post_meta( $post_id, 'owl_mb_content', strip_tags( $_POST['owl_mb_content_one'] ) );
update_post_meta( $post_id, 'owl_mb_title', strip_tags( $_POST['owl_mb_title_one'] ) );
update_post_meta( $post_id, 'owl_mb_content', strip_tags( $_POST['owl_mb_content_two'] ) );
update_post_meta( $post_id, 'owl_mb_title', strip_tags( $_POST['owl_mb_title_two'] ) );
update_post_meta( $post_id, 'owl_mb_content', strip_tags( $_POST['owl_mb_content_three'] ) );
update_post_meta( $post_id, 'owl_mb_title', strip_tags( $_POST['owl_mb_title_three'] ) );
}
?>
Many Thanks :)