[resolved] publish_post without trigger on edit (8 posts)

  1. alexmat
    Posted 8 years ago #

    Is there any action like publish_post that does not trigger when a published post is edited?

    I send out an e-mail whenever a post is published, but don't want it sending e-mails when a post that was published is edited.


  2. Yep. I think it would be draft_to_publish, but you may want to test that theory. It might be new_to_publish instead.


  3. alexmat
    Posted 8 years ago #

    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.


  4. jeckman
    Posted 7 years ago #

    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.

  5. ajaswa
    Posted 7 years ago #

    @jeckman no you'll probably want something like this:

    add_action('future_to_publish', 'function_name');

  6. John Eckman
    Posted 7 years ago #

    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.



    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:


    Since the "false positives" of having it occur when posts are edited is probably minimal impact as opposed to potentially missing a post.

  7. ajaswa
    Posted 7 years ago #


    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:


    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.

  8. pcunix
    Posted 7 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic