Custom post type information disappearing

Here we will discuss about the wordpress general help and support.
  • Ads

Custom post type information disappearing

Postby anshowjingle » Thu Aug 05, 2010 12:43 am

I have created a website where I am using custom post type feature in the new wordpress 3.0. Currently Running RC3 but had issue with RC2 and at this exact moment upgrading to official release of 3.0.

I am using a custom post type called 'bio' for peoples biography. I have 2 custom fields for data, I use the content as well as the post thumbnail. Everything works fine, is added properly and display ok. But I come back the next day and some of my custom fields that I have added seem to disappear ... I have no idea what is going on, please help.
anshowjingle
Jr. Member
Jr. Member
 
Posts: 164
Joined: Fri Jul 30, 2010 12:45 am

Re: Custom post type information disappearing

Postby anshowjingle » Thu Aug 05, 2010 12:44 am

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;
}
}
anshowjingle
Jr. Member
Jr. Member
 
Posts: 164
Joined: Fri Jul 30, 2010 12:45 am

Re: Custom post type information disappearing

Postby jernashelo » Thu Aug 05, 2010 12:45 am

I don't know if you solved your problem, but it seems to come from the Auto-save when editing a draft : http://wordpress.org/support/topic/309612
Try removing Auto-save (http://codex.wordpress.org/Editing_wp-c ... e_Interval) and see if it's better.
It's not really a solution, but it should do the trick for now :)
jernashelo
Jr. Member
Jr. Member
 
Posts: 135
Joined: Fri Jul 30, 2010 12:51 am

Re: Custom post type information disappearing

Postby anshowjingle » Thu Aug 05, 2010 12:45 am

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.
anshowjingle
Jr. Member
Jr. Member
 
Posts: 164
Joined: Fri Jul 30, 2010 12:45 am

  • Ads

Return to Wordpress General Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron