Yep. I think it would be draft_to_publish, but you may want to test that theory. It might be new_to_publish instead.
http://codex.ww.wp.xz.cn/Post_Status_Transitions
Thank you so much. “new_to_publish” works like a charm. Although it wasn’t documented in the link you pointed me to, but that was also useful.
Cheers!
Does new_to_publish happen when scheduled posts get published as well?
I’m looking for an action that is called whenever a post which was not previously published becomes published, but not when an existing post is edited.
@jeckman no you’ll probably want something like this:
add_action('future_to_publish', 'function_name');
Thanks @ajaswa – but does future_to_publish also catch posts that were not scheduled but published immediately?
Sorry if I’m missing something here – but the Post Status Transitions docs aren’t clear to me.
Would
add_action('future_to_publish','function_name');
add_action('new_to_publish','function_name');
together cover all these cases:
- New post, write, publish immediately
- New post, save a draft, edit draft, publish
- New post, schedule for publishing, publish when time arrives, regardless of whether it has been saved as draft and edited or not
Might be easier just to use:
add_action('publish_post','function_name');
Since the “false positives” of having it occur when posts are edited is probably minimal impact as opposed to potentially missing a post.
@johneckman
You are right the docs really suck on this subject. I’ve only figured this out by trial and error.
To cover all 3 of your cases you’ll probably want:
add_action(‘future_to_publish’,’function_name’);
add_action(‘new_to_publish’,’function_name’);
add_action(‘draft_to_publish’,’function_name’);
Something else about this method is from what I can tell it applies to both posts and pages.
I’ve found publish_post to be more annoying then helpful. There really ought to be a hook for just new publishes and one for edits.
When you use add_action(‘publish_post’,’function_name’);
does function_name run BEFORE the post is actually published, sometime during the various actions, or after it is all complete and done?