Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4341220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:27:19+00:00 2026-05-21T11:27:19+00:00

I have created custom post types that also have custom meta_boxes I’ve created. Currently,

  • 0

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($post_id){
    global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
    return $post_id;
}
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 tried calling both at the same time, same issue. What do I need to do differently so I can update a draft (before publishing) and it will save? I’m pretty sure this was working fine before I switched to 3.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:27:20+00:00Added an answer on May 21, 2026 at 11:27 am

    save_post is called no matter what, be it a draft post, or a published post, so I am surprised that is not working. I do see a few oddities with your code though.

    Considering you have the $post_ID, I would favor using that over the global $post. Also, I prefer the following method of detecting auto-drafts (I ripped it straight from wp-includes/post.php, I favor examining the WordPress codebase and emulating their methods whenever possible).

    Please try the following refactored code and let me know if this resolves your issue.

    add_action("save_post", "save_details");
    
    function save_details($post_ID = 0) {
        $post_ID = (int) $post_ID;
        $post_type = get_post_type( $post_ID );
        $post_status = get_post_status( $post_ID );
        if ( "events" == $post_type && "auto-draft" != $post_status ) {
            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"]);
        }
        return $post_ID;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom post type restaurant. But Its not coming on the
I have created a custom post type named People. I have created a page
i have created a custom post type named Books & i have a widget
This post will be heavy on images. I have created a custom ArrayAdapter and
I have created a custom method that will return unique items, together with the
I have created a custom post type of 'portfolio' and page with a template
I have created a custom post type called banners and want to enable the
Using Marius Gedminas's excellent blog post , I have created a custom traverser for
I have created a custom post type calles articles and a custom category like
I have a Wordpress Installation. I have about 3 x custom post types on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.