Is it fired after a post has been published?

Say I have a CPT and want to perform some automated actions based on the post that gets saved, can I do:

    add_action('publish_myt_cpt', 'myfunction');

It is fired in wp-includes/post.php on line 3026 in the following function:

wp-includes/post.php: line 3014-3027

function wp_transition_post_status($new_status, $old_status, $post) {
    do_action('transition_post_status', $new_status, $old_status, $post);
    do_action("{$old_status}_to_{$new_status}", $post);
    do_action("{$new_status}_{$post->post_type}", $post->ID, $post);
| improve this answer | |
  • So is that after the post has been saved? – urok93 Sep 4 '12 at 13:32
  • 90% sure: Yes. You can check by dumping the contents of $post in the add_action. Or add a die('check') in the add_action and check the DB when the die hits – janw Sep 4 '12 at 13:37
  • Right, the post is saved alright, but the post meta isn't yet saved at that point. What I need is to use one of the post meta fields, so I'm stuck. – urok93 Sep 4 '12 at 14:20
  • Well that wasn't your original question. Accept my answer and make a new question or update this one. – janw Sep 5 '12 at 9:39
  • In WordPress 3.5.2 its still in 'wp-includes/post.php', only its moved to line 3270. Up-vote for you sir @janw! – Sy Holloway Sep 12 '13 at 12:20

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.