• I have created custom post types that also have custom meta_boxes I’ve created. Currently, they save when I publish or update a post, but they don’t save when I’m in draft mode making changes.

    add_action('save_post', 'save_details');
    
    function save_details(){
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
        return $post_id;
    }
    global $post;
    if ($post->post_type == 'events') { // Check to see if Event Type.
        update_post_meta($post->ID, "event_featuring", $_POST["event_featuring"]);
        update_post_meta($post->ID, "event_time", $_POST["event_time"]);
        update_post_meta($post->ID, "event_date", $_POST["event_date"]);
        update_post_meta($post->ID, "event_end_date", $_POST["event_end_date"]);
        update_post_meta($post->ID, "event_location", $_POST["event_location"]);
        update_post_meta($post->ID, "empid", $_POST["empid"]);
        update_post_meta($post->ID, "bhs_event", $_POST["bhs_event"]);
    }
    }

    I tried using wp_insert_post_data instead of save_post, but then I had the opposite problem. It would save on Drafts, but publishing the post no longer worked. I also tried using both, but same problem.

    What do I need to do differently so I can update a draft (before publishing) and it will save?

  • The topic ‘Metabox saves on Update or Publish, but not on Saving Draft’ is closed to new replies.