Check for update vs new post on save_post action

Since WordPress version 3.7. – IIRC – the save_post hook – more information about the hook and its usage at Code Reference: save_post and Codex: save_post – has a third parameter $update which can be used to determine just that. @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param … Read more

Using save_post to replace the post’s title

This simplest method would be to edit the data at the point it’s inserted, rather than updating it afterwards, using wp_insert_post_data instead of save_post. This works on creating a new post or updating an existing post without change. It also avoids the danger of creating an infinite loop by triggering update_post within save_post. add_filter( ‘wp_insert_post_data’ … Read more

what is correct way to hook when update post

When a post is updated there are some hooks that are fired: ‘pre_post_update’ is an action fired just before the post is updated, the argument passed are 2: $post_ID and $data that is an array of all the other database colums of the post table ‘transition_post_status’ is an hook fired on update, and pass 3 … Read more

Why does save_post action fire when creating a new post?

When you click ‘New Post’, you’re simply loading the page wp-admin/post-new.php. In doing so, WordPress will always create a new post (an ‘Auto Draft’) to ensure all other features (such as media uploads) and plugins work as normal, even before you actually save a draft or publish the post. And this, in turn, triggers save_post. … Read more