save_post vs post_updated

OK, so let’s start with Codex:

save_post

is an action triggered whenever a post or page is created or updated,
which could be from an import, post/page edit form, xmlrpc, or post by
email. The data for the post is stored in $_POST, $_GET or the global
$post_data, depending on how the post was edited. For example, quick
edits use $_POST.

Since this action is triggered right after the post has been saved,
you can easily access this post object by using get_post($post_id).

It takes 3 params:

  • $post_ID
  • WP_Post $post (post object)
  • bool $update (whether this is an existing post being updated or not.)

post_updated

Use this hook whenever you need to compare values before and after the
post update.

This hook pass up to 3 arguments, as follows:

  • $post_ID ;
  • $post_after (post object after the update);
  • $post_before (post object before the update);

So when should you use which one of them?

post_updated is fired up only if the given post existed before and currently is updated. It won’t get called, when a new post is inserted. It is very useful, if you want to do something with previous version of given post.

save_post is fired up whenever a post is saved. You don’t have easy access to previous version of given post in here (you’ll have to use revisions, if they’re available).

And some more confusion 😉

There is also one more action, you can use:

  • save_post_{$post->post_type} with the same params as save_post, it’s fired up just before save_post and you can use it, if you want to run your code only for given post type.