WordPress.org

Ready to get started?Download WordPress

Forums

problem with edit_post and publish_post hooks (5 posts)

  1. roakin
    Member
    Posted 4 years ago #

    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

  2. Michael Fields
    Themer
    Posted 4 years ago #

    Have you tried the save_post action?

  3. roakin
    Member
    Posted 4 years ago #

    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

  4. Michael Fields
    Themer
    Posted 4 years ago #

    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.

  5. roakin
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic