WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] publish_post action ONLY on publish, not update (3 posts)

  1. thenameisnick
    Member
    Posted 4 years ago #

    I have a series of functions that run when a post is published, but I don't want them to run on any updates to that post.

    I tried testing the 'post_status' with:

    if (!$_POST['post_status'] == 'publish') {
    do stuff
    }

    but to no avail. Any ideas?

    Thanks!

  2. Adam Harley
    Member
    Posted 4 years ago #

    There's probably a cleaner way of doing this, but

    if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) {
    
      echo "New post!";
    
    }

    If you compare the original post status and the new one, that should show whether it's an update or not :)

  3. thenameisnick
    Member
    Posted 4 years ago #

    Kawauso, that seems to be working perfectly. Many thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic