我使用下面的代码为“团队”设置了自定义帖子类型。然而,“最新讨论”和“下一场比赛”的字段没有显示在仪表板中。我反复检查了代码,没有发现任何错误。我希望这里有人能帮我弄清楚。
// Register Teams
add_action(\'init\', \'register_teams\');
function register_teams() {
$labels = array(
\'name\' => _x(\'Teams\', \'post type general name\'),
\'singular_name\' => _x(\'Team\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'team item\'),
\'add_new_item\' => __(\'Add New Team\'),
\'edit_item\' => __(\'Edit Team\'),
\'new_item\' => __(\'New Team\'),
\'view_item\' => __(\'View Team\'),
\'search_items\' => __(\'Search Teams\'),
\'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,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/images/menu-teams.png\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'has_archive\' => true
);
register_post_type( \'teams\' , $args );
}
// Add Fields
add_action("admin_init", "add_teams_fields");
function add_teams_fields(){
add_meta_box("latest_discussion", "Latest Discussion", "latest_discussion", "latest discussions", "side", "low");
add_meta_box("next_fixture", "Next Fixture", "next_fixture", "next fixture", "side", "low");
}
function latest_discussion(){
global $post;
$custom = get_post_custom($post->ID);
$latest_discussion = $custom["latest_discussion"][0];
?>
<label>Latest Discussion URL:</label><br /><br />
<input size="40" name="latest_discussion" value="<?php echo $latest_discussion; ?>" />
<?php
}
function next_fixture(){
global $post;
$custom = get_post_custom($post->ID);
$next_fixture = $custom["next_fixture"][0];
?>
<label>Next Fixture:</label><br /><br />
<input size="40" name="next_fixture" value="<?php echo $next_fixture; ?>" />
<?php
}
// Save Fields
add_action(\'save_post\', \'save_teams_details\');
function save_teams_details(){
global $post;
update_post_meta($post->ID, "latest_discussion", $_POST["latest_discussion"]);
update_post_meta($post->ID, "next_fixture", $_POST["next_fixture"]);
}