Problem with WordPress "save_post" Action Problem with WordPress "save_post" Action php php

Problem with WordPress "save_post" Action


I had this same problem and took a look at the relevant section of post.php. Turns out save_post is called every time post.php runs, so you'll run it on post creation, list, etc.

In WP 3.1, "post_updated" is called only on a save/create event in post.php. So I used:

add_action('post_updated', 'some_function');

Hope this works for you too.


Using the 'post_updated' hook tends to be problematic, particularly when using custom post types. Instead, I used this as my solution:

   function do_save_post($post_id){        $post = get_post($post_id);        if($post->post_status == 'trash' or $post->post_status == 'auto-draft'){                return $post_id;        }        echo "do stuff";    }

I didn't want to perform any actions when items were sent to the trash, either.


This hook runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. So I'd guess it also runs when a post-revision is saved. If I where you I'd check if the postID is set (is the only argument the hook function should get) and if it is a revision wp_is_post_revision().