This is the original answer but it is little faulty, look below for the updated
You can use following approach.
The my_action_updated_post_meta
is executed after the post insert or update is done:
// define the updated_post_meta callback
function my_action_updated_post_meta( $array, $int, $int ) {
global $post;
// see your updated post
print_r($post);
// make your action here...
die('after update');
};
// add the action
add_action( 'updated_post_meta', 'my_action_updated_post_meta', 10, 3 );
Here’s the function’s documentation page.
Update
I have notice that the above response is a little faulty – the updated_post_meta
action (for post updates) is fired also when opening post for edition in the admin panel (since the _edit_lock
is set then), even when no real change is made then.
So I changed the approach.
I use a global variable $my_updated_flag
to know that a “real” change has been made. I set this variable to “1” by post_updated
action. So if $my_updated_flag == 1
we know that this is not just a _edit_lock
change. To differentiate post insert and update action I check the $post->post_status == 'draft'
since new posts have “draft” status at this stage.
$my_updated_flag = 0;
// define the updated_post_meta callback
function action_updated_post_meta( $meta_id, $post_id, $meta_key, $meta_value="" ) {
global $post, $my_updated_flag;
if ($my_updated_flag == 1) {
if ($post->post_status == 'draft') {
die('post_inserted');
} else {
die('post_updated');
}
$my_updated_flag = 0;
}
};
add_action( 'updated_post_meta', 'action_updated_post_meta', 10, 4 );
function action_post_updated( $array, $int, $int ) {
global $my_updated_flag;
$my_updated_flag = 1;
};
add_action( 'post_updated', 'action_post_updated', 10, 3 );