• 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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Yes, save_post happens on every save.

    Maybe you want to use the publish_post instead?

    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.

    Thread Starter glennwelker

    (@glennwelker)

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

    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…

    Cheers,

    Steven

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘save_post called repeatedly’ is closed to new replies.