我正在尝试用wordpress 4创建自定义帖子类型。我阅读了一本名为“从头开始构建Wordpress主题”的教程。我在本地主机上,因此调试模式处于启用状态。
当我尝试创建一个新的CPT时,我得到了表单,但仍然得到了undefined index errors on source, author and date.
我试图通过检查数组索引来解决这个问题,但这两个问题都没有解决。你能帮我解决这个问题吗?
function basin_manager_meta_options(){
global $post;
if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE )
return $post_id;
$custom = get_post_custom($post->ID);
if(isset($custom["source"])){
$source= $custom["source"][0];
}
$author= $custom["author"][0];
$date= $custom["date"][0];
?>
<style type="text/css">
<?php include(\'basin-manager.css\'); ?>
</style>
<div class="basin_manager_extras">
<?php
$website= ($website == "") ? "http://" : $website;
?>
<div><label>Website / Gazete ? :</label>
<input name="source" value="<?php echo $source; ?>" />
</div>
<div><label>Yazar:</label>
<input name="author" value="<?php echo $author; ?>" />
</div>
<div><label>Date:</label>
<input name="date" value="<?php echo $date; ?>" />
</div>
<?php
}
add_action(\'save_post\', \'basin_manager_save_extras\');
function basin_manager_save_extras(){
global $post;
if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ){
//if you remove this the sky will fall on your head.
return $post_id;
}else{
update_post_meta($post->ID, "source", $_POST["source"]);
update_post_meta($post->ID, "author", $_POST["author"]);
update_post_meta($post->ID, "date", $_POST["date"]);
}
}
谢谢。