WordPress.org

Support

Support » How-To and Troubleshooting » problem with edit_post and publish_post hooks

problem with edit_post and publish_post hooks

  • i have following problem. i need fire specific actions whenever a post is published ord edited. therefore i use edit_post and publish_post. my problem is, that whenever i edit a published post, the publish_post action is fired too, which is because ‘publish post’ runs when a post is published, or if it is edited and its status is “published”. but i need an action which is only to run, when the post is published not edited and status published.

    anyone ever had this problem? thx in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you tried the save_post action?

    save_post action takes no concern whether the post hast status ‘draft’ or ‘published’. the thing is i have two wordpress instances and (depending on categories) whenever a post in the leading system is published or edited i generate / edit the post in the second system via XMLRPC. i’ve found a workaround by requesting the status within the function that gets called by the action, but i’m still wondering if there’s a better solution

    i’ve found a workaround by requesting the status within the function that gets called by the action

    I think that this is the best way to address this. IMO the actions just allow us to hook into WordPress at specific points in time. If the action(s) you are using allow you to execute the code that you need to at the specific point in time that you need to, then that is great. I don’t believe that there is any reason to search out a different hook. IMHO if you are checking the value of $post->post_status to create logical structures, this should not be viewed as a workaround, but rather a solution.

    you’re absolutely right. just for information purpose: i switched to ‘save_post’ because when trying to request edited custom field it was necessary to save the post first in database. the logical structure is now created by requesting the status … works perfect

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘problem with edit_post and publish_post hooks’ is closed to new replies.
Skip to toolbar