Question: I have to execute custom PHP code after new post is saved with all it's meta data.

My question is how to achieve that? Tried with **save\_post** action, but it executes before meta records are saved, so I cannot use it in this case.

So, how can I run my custom function after post with all related data is saved in database?

**UPDATED:** I tried to achieve with next code in functions.php file:

```
add_action( 'save_post', 'wpse41912_save_post' );

function wpse41912_save_post() {
// get info about latest added post
    $args = array( 'numberposts' => '1', 'post_type' => 'post' );
    $recent_posts = wp_get_recent_posts( $args );
    $myFunc_latest_id = $recent_posts[0]['ID']; // id of the latest post
    $myFunc_post_details = get_post($myFunc_latest_id);
    print_r($myFunc_post_details);

    // how to execute php code when all post meta is added?

}

```

Thank you in advance!

Answer: 
Quite stupid solution, but works:

```
function afterPostUpdated($meta_id, $post_id, $meta_key='', $meta_value=''){
    if($meta_key=='_edit_lock') {
        if($_GET['message']==1) {
            //
            Your code here
            // 
        }
    }
}
add_action('updated_post_meta', 'afterPostUpdated', 10, 4);

```
You might use this:

```php
function myFunction($post_id, $post, $update ) {
    // your code here
}

add_action('save_post', 'myFunction');

```

`$update` is a boolean and return false if this is a new post. If it's an update it returns true.

Here is the documentation: <https://developer.wordpress.org/reference/hooks/save_post/>