save_post called repeatedly (6 posts)

  1. glennwelker
    Posted 7 years ago #

    I am writing a plugin that has some posted details from the write post page. Capturing this data is working but the function called from the add_action("save_post"... is being called multiple times.

    Is this normal behavior when a user saves a post? If so, what is the proper/recommended way to only act on the posted data once?

  2. Yes, save_post happens on every save.

    Maybe you want to use the publish_post instead?

  3. Technokinetics
    Posted 7 years ago #

    The save_post action is called twice on every save. You could use a flag to only execute whatever code you're hooking into it once per save.

  4. glennwelker
    Posted 7 years ago #

    Thanks. I ended up looking for the post_type and ignoring revisions.

  5. Steven
    Posted 7 years ago #

    Hi glennwelker,

    How did you solve this? Can you post your solution?

    I'm having the same issue with the plugin I'm writing which uses a extra database table. It appears that the save_post action gets activated twice upon saving the post so it saves 2 records to the database: one with the revision post id and one with the original post id...



  6. wordpress4you
    Posted 6 years ago #

    Plugin API/Action Reference reads:

    Note that post ID may reference a post revision and not the last saved post. Use wp_is_post_revision to get the ID of the real post.

    Hope that will help.

Topic Closed

This topic has been closed to new replies.

About this Topic