Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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);
}
share|improve this answer
    
So is that after the post has been saved? –  drtanz 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. –  drtanz 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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