WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see the following pattern over and over, on this site and on other places:

add_action( 'save_post', 'wpse14169_save_post' );
function wpse14169_save_post( $post_id )
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return $post_id;
    // Other code...

Why should I return $post_id? save_post is an action, and the return value of an action handler is ignored. The WordPress core itself doesn't do it either.

The Codex example does return the $post_id, but it would not be the first incorrect (or outdated) line in the Codex.

Am I missing something? Do I need to return $post_id? Was there a there a time when this was needed?

share|improve this question
For reference here is edit that introduced early version of this to Codex. I do not recognize the login, you could try to look person up and ask (if that interested). – Rarst Apr 7 '11 at 14:37
up vote 4 down vote accepted

The 'save_post' action was added to core in 2.0, and has always been an action. Looking through the current autosave procedures, it doesn't appear to call the 'save_post' action directly at any time.

So the short answer is, no. There is no reason, and has never been any reason, to return any value on this action. Of course, it doesn't hurt at all to do return the post id.

share|improve this answer

Since nothing is being done with the return value, returning the post ID is pointless and should not be done. It only provides room for confusion.

Just tried it out, the following save_post action works fine.

function my_save_post($post_id)
    // Stop WP from clearing custom fields on autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)

    // Prevent quick edit from clearing custom fields
    if (defined('DOING_AJAX') && DOING_AJAX)

    // Sanitize, validate and save ...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.