A Post is saved twice or more during add_action(save_post)

One of the two IDs might be a post revision. To prevent this behaviour, I always have this checks in my save_postdata function:

// Autosave, do nothing
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return;
// AJAX? Not used here
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) 
        return;
// Check user permissions
if ( ! current_user_can( 'edit_post', $post_id ) )
        return;
// Return if it's a post revision
if ( false !== wp_is_post_revision( $post_id ) )
        return;

As you can see, the last condition I use here checks for the post revision. Try to use this in your function, too.

Leave a Comment