I have two custom meta fields that I’ve enabled for each post, scottb_customHeader and scottb_customTitle
These work fine as long as I’m using the full edit feature to edit posts. However, when I click “Quick Edit”, then click “Update”, my custom meta values for the post are cleared out. What do I need to do to resolve?
Code is below…
add_action('save_post', 'custom_add_save');
function custom_add_save($postID){
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $postID;
}
else
{
// called after a post or page is saved
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}
if ($_POST['scottb_customHeader'])
{
update_custom_meta($postID, $_POST['scottb_customHeader'], '_scottb_customHeader');
}
else
{
update_custom_meta($postID, '', '_scottb_customHeader');
}
if ($_POST['scottb_customTitle'])
{
update_custom_meta($postID, $_POST['scottb_customTitle'], '_scottb_customTitle');
}
else
{
update_custom_meta($postID, '', '_scottb_customTitle');
}
}
}
function update_custom_meta($postID, $newvalue, $field_name) {
// To create new meta
if(!get_post_meta($postID, $field_name)){
add_post_meta($postID, $field_name, $newvalue);
}else{
// or to update existing meta
update_post_meta($postID, $field_name, $newvalue);
}
}