“Quick Edit” > update clears out my custom meta values

Add a hidden flag to the post edit form along with your custom fields. Something like

<input type="hidden" name="my_hidden_flag" value="true" />

Then, wrap all of your custom save_post stuff in a check for this flag. Then you don’t have to check for the autosave constant any more either–if the flag doesn’t exist, it’s either a quick edit or an autosave.

function custom_add_save($postID){

    // Only do this if our custom flag is present
    if (isset($_POST['my_hidden_flag'])) {

        // 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');
        }

    }

}

Leave a Comment