您的代码中有几个错误。
NOTE: You should debug your errors using your error logs. :|
首先,您添加
register_post_type( \'businesses\' , $args );
在您的
local_business_directory_register()
作用
其次,你在引用$post_id
在两个不同的地方,没有设置变量。因为您定义global $post
, 您可以参考post ID 使用$post->ID
<?php
/*
Plugin Name: Special Coffee CPT
Plugin URI: http://danijoypractice.x10host.com
Description: This plugin creates a custom post type & template page
Author: Danielle Rautiainen
Version: 1.0
Author URI: http://danijoypractice.x10host.com
*/
add_action(\'init\', \'local_business_directory_register\');
function local_business_directory_register() {
$args = array(
\'label\' => __(\'Business Directory\'),
\'singular_label\' => __(\'Business\'),
\'public\' => true,
\'taxonomies\' => array(\'category\'),
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true,
\'supports\' => array(\'title\', \'editor\', ),
\'rewrite\' => array(\'slug\' => \'businesses\', \'with_front\' => false),
);
register_post_type( \'businesses\' , $args );
}
register_taxonomy("business-type", array("businesses"), array(
"hierarchical" => true,
"label" => "Business Type",
"singular_label" => "Business Type",
"rewrite" => true
)
);
add_action("admin_init", "local_business_directory_meta");
function local_business_directory_meta ()
{
add_meta_box("business-meta", "Business Options", "local_business_directory_options", "businesses", "normal", "high");
}
function local_business_directory_options()
{
global $post;
if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) return $post->ID;
$custom = get_post_custom($post->ID);
$address = $custom["address"][0];
$website = $custom["website"][0];
$phone = $custom["phone"][0];
?>
<style type="text/css">
<?php include(\'business-directory.css\'); ?>
</style>
<div class="business_directory_extras">
<?php $website= ($website == "") ? "http://" : $website; ?>
<div>
<label>Website:</label>
<input name="website" value="<?php echo $website; ?>" />
</div>
<div>
<label>Phone:</label>
<input name="phone" value="<?php echo $phone; ?>" />
</div>
<div>
<label>Address:</label>
<textarea name="address"><?php echo $address; ?>" /></textarea>
</div>
</div>
<?php
}
add_action(\'save_post\', \'local_business_directory_save_extras\');
function business_manager_save_extras(){
global $post;
if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ){
return $post->ID;
}else{
update_post_meta($post->ID, "website", $_POST["website"]);
update_post_meta($post->ID, "address", $_POST["address"]);
update_post_meta($post->ID, "phone", $_POST["phone"]);
}
}
?>