I have the following code. I am trying to enter data into the custom metabox and then save it. When I go to view it has entered a post, however the name column has nothing in it. Also when I hit save I get a post.php page with a blank page, is this a page I need to create in my theme and have it go back to the current page or something.
<?
/**
* Custom post-type booktime
**/
add_action('init', 'booktime_register');
function booktime_register() {
$labels = array(
'name' => _x('booktime', 'post type general name'),
'singular_name' => _x('booktime', 'post type singular name'),
'add_new' => _x('add new', 'add new'),
'add_new_item' => __('add new item'),
'edit_item' => __('edit item'),
'new_item' => __('new item'),
'view_item' => __('view item'),
'search_items' => __('search items'),
'not_found' => __('nothing here'),
'not_found_in_trash' => __('not found in trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail','comments','custom-fields','revisions')
);
register_post_type( 'booktime' , $args );
}
?>
<?php
add_action("manage_posts_custom_column", "booktime_custom_columns");
add_filter("manage_edit-booktime_columns", "booktime_edit_columns");
function booktime_custom_columns($column){
global $post;
switch ($column) {
case "name":
the_excerpt();
break;
case "address":
$custom = get_post_custom();
echo $custom["address"][0];
break;
case "phone":
$custom = get_post_custom();
echo $custom["phone"][0];
break;
case "date":
$custom = get_post_custom();
echo $custom["date"][0];
break;
case "bottles":
$custom = get_post_custom();
echo $custom["bottles"][0];
break;
}
}
function booktime_edit_columns($columns){
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Post should show",
"description" => "name",
"address" => "address",
"phone" => "phone",
"date" => "date",
"bottles" => "bottles"
);
return $columns;
}
?>
<?php
add_action("admin_init", "admin_init_booktime");
function admin_init_booktime(){
add_meta_box("name", "name", "name", "booktime", "normal", "low");
}
?>
<?php
function name() {
global $post;
$custom = get_post_custom($post->ID);
$name = ( !empty($custom["name"][0]) ) ? $custom["name"][0]: "";
?>
<p><label>Name:</label><br />
<input type="text" name="name" value="<?php echo $name; ?>"/></p>
<?php
}
?>
<?php
add_action('save_post', 'save_details_booktime');
function save_details_booktime(){
global $post;
$custom_meta_fields = array( 'name' );
foreach( $custom_meta_fields as $custom_meta_field ):
if(isset($_POST[$custom_meta_field]) && $_POST[$custom_meta_field] != ""):
update_post_meta($post->ID, $custom_meta_field, $_POST[$custom_meta_field]);
endif;
endforeach;
}
?>