glennwelker
Member
Posted 3 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?
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.
glennwelker
Member
Posted 3 years ago #
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
wordpress4you
Member
Posted 2 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.