我有以下代码用于创建自定义帖子类型。一切正常保存功能正在触发,似乎正在保存。但我无法将保存的数据输出到页面编辑的文本字段中。我已经盯着它玩了好几天了。在线查看了每个教程。我想不出我在这里遗漏了什么。任何帮助都将不胜感激。
我试着改变10,2
但没有帮助。我尝试在save函数中编写新代码,您可以看到它被注释掉了,这也不起作用。
// Registers the new post type and taxonomy
function course_listing_posttype() {
register_post_type( \'courses\',
array(
\'labels\' => array(
\'name\' => __( \'Course Listings\' ),
\'singular_name\' => __( \'Course Listing\' ),
\'add_new\' => __( \'Add New Course\' ),
\'add_new_item\' => __( \'Add New Course Listing\' ),
\'edit_item\' => __( \'Edit Course Listing\' ),
\'new_item\' => __( \'Add New Course Listing\' ),
\'view_item\' => __( \'View Course Listing\' ),
\'search_items\' => __( \'Search Course Listing\' ),
\'not_found\' => __( \'No Course Listings found\' ),
\'not_found_in_trash\' => __( \'No Course Listings found in trash\' )
),
\'public\' => true,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'capability_type\' => \'post\',
\'rewrite\' => array("slug" => "courses"), // Permalinks format
\'menu_position\' => 5,
\'taxonomies\' => array( \'regional\', \'national\', \'global\'), //figure out how to show this
\'register_meta_box_cb\' => \'add_course_listing\'
)
);
}
add_action( \'init\', \'course_listing_posttype\' );
// Add Meta Boxes
function add_course_listing() {
//meta for application deadline
add_meta_box(\'course_listing_meta\', \'Course Listing Details\', \'course_listing_meta\', \'courses\', \'normal\', \'default\');
}
add_action("add_meta_boxes", "add_course_listing");
//application deadline meta
function course_listing_meta($object) {
global $post;
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<label for="application_deadline"><strong>Application Deadline:</strong></label><br>
<i>Select the deadline for the course application</i><br>
<input type="text" id="application_deadline" name="application_deadline" value="<?php echo get_post_meta($object->ID, \'application_deadline\', true); ?>" size="120">
<br><br>
<label for="workshop_date"><strong>On-Site Workshop Dates:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<input type="text" id="workshop_date" name="workshop_date" value="<?php echo get_post_meta($object->ID, \'workshop_date\', true); ?>" size="120">
<br><br>
<label><strong>Contact Information:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<textarea type="text" id="contact_information" name="contact_information" value="<?php echo get_post_meta($object->ID, \'contact_information\', true); ?>" rows="10" cols="120"></textarea>
<br><br>
<label><strong>Directions:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<textarea type="text" id="directions" name="directions" value="<?php echo get_post_meta($object->ID, \'directions\', true); ?>" rows="10" cols="120"></textarea>
<br><br>
<label><strong>Hotels and Lodging:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<textarea type="text" id="lodging" name="lodging" value="<?php echo get_post_meta($object->ID, \'lodging\', true); ?>" rows="10" cols="120"></textarea>
<br><br>
<label><strong>Veterinarians Nearby:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<textarea type="text" id="veterinarians" name="veterinarians" value="<?php echo get_post_meta($object->ID, \'veterinarians\', true); ?>" rows="10" cols="120"></textarea>
<br><br>
<label><strong>State:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<input type="text" id="state" name="state" value="<?php echo get_post_meta($object->ID, \'state\', true); ?>" size="120">
<br><br>
<label><strong>Zip Code:</strong></label><br>
<i>Lorem ipsum dorem doleorum fibrouich forloer kolem lorey</i><br>
<input type="text" id="zip" name="zip" value="<?php echo get_post_meta($object->ID, \'zip\', true); ?>" size="120">
<br><br>
<?php
}
// Save the Metabox Data
function wpt_save_events_meta($post_id, $post) {
/*
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
return $post_id;
if(!current_user_can("edit_post", $post_id))
return $post_id;
*/
//global $post;
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
return $post_id;
/*
$slug = "post";
if($slug != $post->post_type)
return $post_id;
*/
$meta_box_text_value = "";
$meta_box_dropdown_value = "";
$meta_box_checkbox_value = "";
if ( isset( $_POST[\'contact_information\'] ) && $_POST[\'contact_information\'] != \'\' ) {
update_post_meta( $meta_box_text_value, \'courses\', $_POST[\'contact_information\'] );
}
/*
//save workshop date
if(isset($_POST["contact_information"]))
{
$meta_box_text_value = $_POST["contact_information"];
}
update_post_meta($post_id, "contact_information", $meta_box_text_value);
*/
}
add_action(\'save_post\', \'wpt_save_events_meta\', 10, 2); // save the custom fields