I have the following code used to create a Custom Post Type. All works the save function is being triggered, and it seems to be saving. But I cannot get the saved data to output in the text field on Page Edit. I've stared at this and played around with it for days now. Looked at every tutorial online. I can't figure out what I am missing here. Any help would be great appreciated.
I tried changing the 10,2
but doesn't help. I tried writing new code in the save function that you can see is commented out and this doesn't work either.
// 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