WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several functions that are called from inside a save_post function. However, all of the functions that use the $post object are returning incorrect values because it appears that the default value being passed to save_post is the post ID rather than the post object.

How can I pass the post object to the save_post function in addition to the post ID?

add_action('save_post', 'my_save_function');
share|improve this question
up vote 4 down vote accepted


add_action('save_post', 'my_save_function', 10, 2);

And the $post object will be passed as second argument to your function:

function my_save_function($post_ID, $post) {
share|improve this answer
@sorich: I'm getting an different (and incorrect) value for $post->ID echo inside the "my_save_function" than when its echo'd outside that function. Any ideas? – Scott B Nov 1 '10 at 17:14
Do you mean echo $post_ID and echo $post->ID return different results? – sorich87 Nov 1 '10 at 17:19
Every time I test, the value of $post_ID, it gets incremented by one. Its as if this were a draft version ID incrementing. Any ideas? – Scott B Nov 1 '10 at 17:21
$post_ID and $post->ID are the same. However, the value being returned is in the 300's (increments by one each time i click "Publish" to test). My post id should be 176 – Scott B Nov 1 '10 at 17:24
I am not sure, but I think it has something to do with the post revision. Are the values of $post->post_content and $post->post_title correct? – sorich87 Nov 1 '10 at 17:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.