为什么此帖子类型中的自定义字段不保存?
我有一个称为照片的自定义帖子类型和几个元框。这是我的函数中的基本内容。php
add_action(\'init\', \'photo_register\');
function photo_register() {
$labels = array(
\'name\' => _x(\'My Photos\', \'post type general name\'),
\'singular_name\' => _x(\'Photo\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'photo item\'),
\'add_new_item\' => __(\'Add New Photo\'),
\'edit_item\' => __(\'Edit Photo\'),
\'new_item\' => __(\'New Photo\'),
\'view_item\' => __(\'View Photo\'),
\'search_items\' => __(\'Search Photos\'),
\'not_found\' => __(\'Nothing found\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
//\'menu_icon\' => get_stylesheet_directory_uri() . \'/article16.png\',
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => 4,
\'taxonomies\' => array(\'post_tag\',\'category\'),
\'supports\' => array(\'title\',\'comments\',\'trackbacks\',\'revisions\',\'custom-fields\',\'page-attributes\',\'thumbnail\', \'excerpt\', \'tags\')
);
register_post_type( \'photo\' , $args );
register_taxonomy("Photos", array("photo"), array("hierarchical" => true, "label" => "Photos", "singular_label" => "Photo", "rewrite" => true));
}
add_action("admin_init", "admin_init");
add_action(\'save_post\', \'save_details\');
function admin_init(){ // add_meta_box( $id, $title, $callback, $page, $context, $priority );
add_meta_box("media", "Media Type", "media", "photo", "side", "high");
add_meta_box("map_meta", "Mapping Info", "map_meta", "photo", "normal", "high");
add_meta_box("photo_meta", "Add a photograph", "photo_meta", "photo", "normal", "high");
}
function media(){
global $post;
$custom = get_post_custom($post->ID);
$film = $custom["film"][0];
$camera = $custom["camera"][0];
?>
<label>Camera:</label>
<input name="camera" value="<?php echo $camera; ?>" />
<label>Film:</label>
<input name="film" value="<?php echo $film; ?>" />
<?php
}
function photo_meta(){
global $post;
$custom = get_post_custom($post->ID);
$single_photo = $custom["single_photo"][0];
?>
<div id="singleUpload">
<div class="sUinput">
<input id="single_photo" name="single_photo" value="<?php echo $single_photo; ?>" />
</div>
<div class="sUbutton">
<input type="button" value="Upload" name="upload" id="upload_image_button" />
</div>
</div>
<?php
}
function map_meta() {
global $post;
$custom = get_post_custom($post->ID);
$latitude = $custom["latitude"][0];
$longitude = $custom["longitude"][0];
?>
<div id="mapControls">
<div class="lat">
<p><label for="lat">Latitude:</label><br />
<input id="latitude" name="latitude" value="<?php echo $latitude; ?>"></input></p>
</div>
<div class="lng">
<p><label>Longitude:</label><br />
<input id="longitude" name="longitude" value="<?php echo $longitude; ?>" ></input></p>
</div>
<?php }
function save_details(){
global $post;
update_post_meta($post->ID, "single_photo", $_POST["single_photo"]);
update_post_meta($post->ID, "latitude", $_POST["latitude"]);
update_post_meta($post->ID, "longitude", $_POST["longitude"]);
update_post_meta($post->ID, "camera", $_POST["camera"]);
update_post_meta($post->ID, "film", $_POST["film"]);
}
我让它工作了一段时间,但现在它不会保存字段,刷新会擦除所有内容。有人知道问题出在哪里吗?有没有关于如何找到bug的建议?基本上,你能想到的任何改进都将不胜感激,尤其是如果我能让它发挥作用的话!
编辑我发现它们确实可以保存,但如果我在帖子上停留的时间足以运行自动保存,然后尝试导航离开,我会收到消息:
页面要求您确认是否要离开-您输入的数据可能不会保存。
我单击“离开”,然后当我返回帖子时,所有内容都被删除。这是怎么回事?