我有以下代码。我正在尝试将数据输入自定义元数据库,然后保存它。当我去查看时,它已经进入了一个帖子,但是name列中没有任何内容。当我点击save时,我也得到了一个帖子。带有空白页面的php页面,这是我需要在我的主题中创建的页面,并将其返回到当前页面或其他页面。
<?
/**
* 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;
}
?>