WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.