Access post meta just after publishing

the following code is supposed to store post meta of the recently published post to the variable $temp. But it doesn't, $temp is always empty. This seems to happen because "transition_post_status" fires before meta information is stored to the database.

Is there a hook that makes me able to get the post meta of the post I just published?

function myfunction($new_status, $old_status, $post) {
     if ($post-post_status !== "publish" ) {
       return; }

     $temp = get_post_meta($post-ID);
     // do something with post meta information
}
add_action('transition_post_status', 'myfunction', 10, 3);

Topic post-meta hooks publish Wordpress

Category Web


Here is the description of transition_post_status from the codex:

This function's access is marked as private. That means it is not intended for use by plugin and theme developers, but only in other core functions. It is listed here for completeness. Use any of these functions instead.

Why not use the publish_post action instead? There is a nice article + example in the codex which covers your case. It sends an email whenever a post is published and sends the post data.

Edit 1: As @Pieter Goosen pointed I've looked at different function (_transition_post_status() instead of the hook transition_post_status). Please disregard my post about it's description. Sorry for the confusion!

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.