Top Commentators

OnTheRoad

  • Two guys and a Beer - Episode 85
  • Jam Session 2
  • Two guys and a Beer - Episode 84

WordPress: ‘publish_post’ is also triggered on subsequent post editions

If you ever dug into the wordpress plugin world you know that you can create some hooks on the wordpress flow to allow execution of your functions when something interesting happens. One of those hooks is the ‘publish_post’, which will be triggered when the post is published and – surprise – also everytime the post is edited and it’s status is published.

I recently had to dwell into this because I wanted my blog to post to twitter (and other sites) *only* when the post was actually published. I.e.: I don’t want to spam people everytime I update a post.

So it turns out there are some other hooks you can set instead, that will do the trick, namely:

add_action('draft_to_publish', 'example');
add_action('pending_to_publish', 'example');

The first one will run function ‘example’ (with the post_id as the single argument, by the way) when a post transitions from the draft to the published status. The second will do the same on the pending to published transition.

No clue why the wordpress folks made it so the ‘publish_post’ hook also triggers when the posts are updated, but they must have their reasons :)

Related:

  1. Other (probably intelligent) wordpress plugins to install Following up on my post about RAM (or lack of...
  2. Migrated the blog to wordpress Yes, once again. I know, I have no life I’m...

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

2 comments to WordPress: ‘publish_post’ is also triggered on subsequent post editions

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>