I have a problem. I'm trying to add a meta box textarea field to a custom post type (in a plugin) with custom database table. The meta box is displaying in the custom post type, saving and updating, but just not showing the data on a page (front end) and I just can't figure it out. It shows the title and content of the post, but not the entered data. Here is my code for meta box:
//show metabox in post editing page
add_action('add_meta_boxes', 'bsp_add_metabox' );
function bsp_add_metabox() {
// add_meta_box( $id, $title, $callback, $screen, $context, $priority );
add_meta_box('bsp_mother_tongue', 'Mother language','bsp_mother_tongue_handler', 'badge','normal');
}
//showing the meta box on admin page
function bsp_mother_tongue_handler($post){
$value = get_post_custom($post->ID);
?>
<!--<label for="bsp_text_meta">Mother language </label><br />-->
<textarea id="bsp_text_meta" name="bsp_text_meta" class="widefat" style="overflow:auto; resize:none" rows="15"><?php if(isset($value['bsp_text_meta'])) {echo $value['bsp_text_meta'][0]; } ?></textarea>
//check if user can edit post
if( !current_user_can( 'edit_posts' ) ) {
return;
}
if( isset($_POST['bsp_text_meta'] )) {
update_post_meta($post_id, 'bsp_text_meta', esc_attr($_POST['bsp_text_meta']));
}
}
badge is the name of a custom post type (slug).