Not able to save Custom Posts Types
-
Hi,
I am using custom post types for the first time and have managed to get everything working except when I try and save the meta information.
I’d appreciate it if someone could have a look at the code below and see where I might be going wrong with this please.add_action( 'init', 'sh_spotting' ); function sh_spotting() { $labels = array( 'name' => __( 'Calendars' ), 'singular_name' => __( 'Calendar' ), 'add_new' => _x('Add New Event',''), 'add_new_item' => __('Add New Event',''), 'edit_item' => __('Edit Event', ''), 'view_item' => __('View Event',''), 'search_items' => __('Search Events',''), 'not_found' => __('No Such Event',''), 'parent_item_colon' => '', 'menu_name' => __('Events',''), ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'exclude_from_search' => false, 'menu_position' => 5, 'hierarchical' => false, 'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ) ); register_post_type('spotted', $args); } add_action("admin_init", "admin_init"); add_action('save_post', 'save_sh_event'); function admin_init() { add_meta_box("shEvent-meta", "Event Details", "meta_options", "spotted", "side", "low"); } function meta_options() { global $post; $custom = get_post_custom($post->ID); $match_against = $custom["match_against"][0]; $match_venue = $custom["match_venue"][0]; $match_tournament = $custom["match_tournament"][0]; ?> <div class="sh_events"> <label>Playing against:</label><input name="match_against" value="<?php echo $match_against; ?>" /> <label>Playing where:</label><input name="match_venue" value="<?php echo $match_venue; ?>" /> <label>Tournament:</label><input name="match_tournament" value="<?php echo $match_tournament; ?>" /> <p>Please use the <strong>Publish</strong> settings box to set the event date and time</p> </div> <?php } // I think I might be going wrong here somewhere? function save_sh_event(){ global $post; update_post_meta($post->ID, "match_against", $_POST["match_against"]); update_post_meta($post->ID, "match_venue", $_POST["match_venue"]); update_post_meta($post->ID, "match_tournament", $_POST["match_tournament"]); } register_taxonomy("sh-events", array("shark-spotting"), array("hierarchical" => true, "label" => "Event Categories", "singular_label" => "Event", "rewrite" => true));
Many thanks
[No bumping, thank you.]
- The topic ‘Not able to save Custom Posts Types’ is closed to new replies.