Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter landonpoburan

    (@landonpoburan)

    I have solved this issue.

    You need to add a conditional statement checking to make sure that data is present before actually updating custom fields. This is because the autosave feature does not grab all the data, it only grabs the title and post content so when it autosaves it erases all the other data.

    Thread Starter landonpoburan

    (@landonpoburan)

    Here is the code being used for one instance.

    /**
     *
     * CUSTOM POST TYPE FOR THE-WORK
     *
     */	
    
    	// add the custom post type
     	add_action('init', 'create_case');
    	function create_case() {
        	$bio_args = array(
            	'label' => __('Case Study'),
            	'singular_label' => __('Case Study'),
            	'public' => true,
            	'show_ui' => true,
            	'capability_type' => 'post',
            	'hierarchical' => false,
            	'rewrite' => true,
            	'supports' => array('title', 'editor', 'thumbnail', 'excerpt')
            );
        	register_post_type('case',$bio_args);
    	}
    
    	// add custom fields
    	add_action("admin_init", "add_case");
    	add_action('save_post', 'update_case');
    
    	function add_case(){
    		add_meta_box("case_details", "Case Study Information", "case_options", "case", "normal", "low");
    	}
    
    	function case_options() {
    		global $post;
    		$custom = get_post_custom($post->ID);
    		$cs_subhead = $custom["cs_subhead"][0];
    		$cs_thumbnail = $custom["cs_thumbnail"][0];
    		$cs_thumbnail_hover = $custom["cs_thumbnail_hover"][0];
    
    		?>
    		<div id="case-options">
    			<label>Sub Headline: </label><input name="cs_subhead" value="<?php echo $cs_subhead; ?>" style="width: 450px;" />
    			<br />
    			<label>Thumbnail: </label><input name="cs_thumbnail" value="<?php echo $cs_thumbnail; ?>" style="width: 450px;" />
    			<br />
    			<label>Thumbnail Hover: </label><input name="cs_thumbnail_hover" value="<?php echo $cs_thumbnail_hover; ?>" style="width: 450px;" />
    		</div><!--end bio-options-->
    		<?php
    	}
    
    	function update_case() {
    
    		if (isset($_POST['cs_subhead']) && isset($_POST['cs_thumbnail']) && isset($_POST['cs_thumbnail_hover'])) {
    
    			global $post;
    			update_post_meta($post->ID, "cs_subhead", $_POST["cs_subhead"]);
    			update_post_meta($post->ID, "cs_thumbnail", $_POST["cs_thumbnail"]);
    			update_post_meta($post->ID, "cs_thumbnail_hover", $_POST["cs_thumbnail_hover"]);
    
    		}
    	}
    
    	// modifying the overview page
    	add_filter("manage_edit-case_columns", "case_edit_columns");
    	add_action("manage_posts_case_column",  "case_columns_display");
    
    	function case_edit_columns($case_columns){
    		$case_columns = array(
    			"cb" => "<input type=\"checkbox\" />",
    			"title" => "Case Study",
    			"description" => "Description",
    		);
    		return $case_columns;
    	}
    
    	function case_columns_display($case_columns){
    		global $post;
    
    		switch ($case_columns)
    		{
    			case "description":
    				the_excerpt();
    				break;
    		}
    	}

Viewing 2 replies - 1 through 2 (of 2 total)