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);
  • 1
    Please do not post duplicates, and do not use different accounts to post the same question. You might get help if you stick to one trusted account :-) – Pieter Goosen Aug 3 '15 at 16:28
  • Sorry. I posted the other post as a guest and edited it as registered user. For some reason I couldn't add comments to the answers, so I started a new try. – Christian O. Aug 3 '15 at 21:45

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!

| improve this answer | |
  • transition_post_status hook !== _transition_post_status() function. Using the transition_post_status hook is perfectly fine :-) – Pieter Goosen Aug 3 '15 at 18:22
  • Aaah yes. My bad. Missed the underscore and trusted Google a bit too much (Lazy level +1). Will edit post not to mislead somebody. – denis.stoyanov Aug 3 '15 at 18:43
  • Thanks for your answers. But the problem is, I can't access meta data of the post via get_post_meta(), which outputs an empty array. But I need to get access to the meta data, because one of them is an automatically generated ID, not identical to the ID of the post itself. – Christian O. Aug 3 '15 at 21:41
  • I have tried publish_post, save_post, transition_post_status hooks - all of them didn't return the meta data of the post. wp_insert_post did it, but it fired 76 times, I need it to do it just once. Anyone an idea how to solve that? – Christian O. Aug 4 '15 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.