Custom Post Type Save/Update Malfunction
-
Hoping someone can easily make me feel stupid because I’m banging my head on something probably really small that I’ve over looked here. I’ve created a custom post type, which also creates some categories when the theme is activated- all that is good. I also am creating several custom meta boxes, which is where the problem lies. If input data into the meta boxes and hit save/update/publish everything is fine. If i come back, and hit update in the future the meta boxes that I did not put in new data are lost. (only the newly updated meta boxes are saved and it deletes the others)
Here’s the entire post type:
<? //register post type function register_resume() { $labels = array( 'name' => _x( 'Resume', 'post type general name' ), 'singular_name' => _x( 'resume', 'post type singular name' ), 'add_new' => _x( 'Add New', 'book' ), 'add_new_item' => __( 'Add New Resume Item' ), 'edit_item' => __( 'Edit Items' ), 'new_item' => __( 'New Item' ), 'all_items' => __( 'All Resume Items' ), 'view_item' => __( 'View Resume Items' ), 'search_items' => __( 'Search Resume Items' ), 'not_found' => __( 'No items found' ), 'not_found_in_trash' => __( 'No items found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Resume' ); $args = array( 'labels' => $labels, 'description' => 'Holds our resume and resume specific data', 'public' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor'), 'has_archive' => false, 'taxonomies' => array('Education','Work','Code','Software'), 'register_meta_box_cb' => 'declare_meta_boxes' ); register_post_type( 'resume', $args ); } add_action( 'init', 'register_resume' ); //create taxonomy function taxonomy_resume() { $labels = array( 'name' => _x( 'Resume', 'taxonomy general name' ), 'singular_name' => _x( 'Resume Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Resume Categories' ), 'all_items' => __( 'All Resume Categories' ), 'parent_item' => __( 'Parent Resume Category' ), 'parent_item_colon' => __( 'Parent Resume Category:' ), 'edit_item' => __( 'Edit Resume Category' ), 'update_item' => __( 'Update Resume Category' ), 'add_new_item' => __( 'Add New Resume Category' ), 'new_item_name' => __( 'New Resume Category' ), 'menu_name' => __( 'Resume Categories' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, ); register_taxonomy( 'resume_category', 'resume', $args ); } add_action( 'init', 'taxonomy_resume', 0 ); function add_resume_categories() { $categories = array("Education","Work","Code","Software","Skills", "Awards"); foreach($categories as $category): wp_insert_term($category,'resume_category'); endforeach; } add_action( 'after_switch_theme', 'add_resume_categories' ); function declare_meta_boxes($post){ declare_copy_text_meta_box($post); declare_acommplishments_meta_box($post); } function save_meta_boxes($post){ copy_text_save_metabox($post); acommplishments_save_metabox($post); } add_action('save_post', 'save_meta_boxes'); function declare_copy_text_meta_box($post){ add_meta_box( 'copy_text_meta_box', 'Degree or Job Title', 'copy_text_meta_box', $post->post_type, 'normal' , 'low' ); } function copy_text_save_metabox(){ global $post; if(isset($_POST["copy_text"])){ //UPDATE: $meta_element_class = $_POST['copy_text']; //END OF UPDATE update_post_meta($post->ID, 'copy_text_meta_box', $meta_element_class); //print_r($_POST); } } function copy_text_meta_box($post){ $meta_element_class = get_post_meta( $post->ID, 'copy_text_meta_box', true ); ?> <label>List Degree or Job Title: </label> <input type="text" name="copy_text" id="copy_text" placeholder="<?=$meta_element_class?>"/> <?php } $accomplishment_total = 5; function declare_acommplishments_meta_box($post){ add_meta_box( 'acommplishments_meta_box', 'Accomplishments', 'acommplishments_meta_box', $post->post_type, 'normal' , 'low' ); } function acommplishments_save_metabox($accomplishment_total){ global $accomplishment_total; global $post; $accomplishment_total ? $accomplishment_total : $accomplishment_total = 1; for ($i=1; $i<=$accomplishment_total; $i++): if(isset($_POST["acommplishments$i"])): //UPDATE: $meta_element_class = $_POST["acommplishments$i"]; //END OF UPDATE update_post_meta( $post->ID, "acommplishments_meta_box$i", $meta_element_class); endif; endfor; } function acommplishments_meta_box($post){ global $accomplishment_total; $accomplishment_total ? $accomplishment_total : $accomplishment_total = 1; for ($i=1; $i<=$accomplishment_total; $i++): $meta_element_class = get_post_meta( $post->ID, "acommplishments_meta_box$i", true ); ?> <label>Accomplishment <?=$i?>:</label> <input type="text" name="acommplishments<?=$i?>" id="acommplishments<?=$i?>" placeholder="<?=$meta_element_class?>"/> <div class="clear"></div> <?php endfor; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Post Type Save/Update Malfunction’ is closed to new replies.