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

My plugin uses publish_post hook to get the post data and do some processing:

add_action('publish_post', 'publish_post');

function publish_post($post_id) {
      global $post, $blog_id;
      $author = get_userdata ($post->post_author);
      $title = $post->post_title;
      //some processing here...

I notice that for a new post, $title is always blank, while all other fields are available. If I publish the post again (update), then the title becomes available.


I printed out the $post variable and notice that that the post_status is draft:

[post_title] =>
[post_excerpt] =>
[post_status] => draft

So it seems the $post variable contains what was loaded from the database, but not what is currently on the screen. How should I get the $post that reflects what is currently on the screen? Is there a hook that fires after a post is saved to the database?

share|improve this question
up vote 2 down vote accepted

This hook is called like this:

do_action("{$new_status}_{$post->post_type}", $post->ID, $post);

My guess is that you should be using data passed as second $post argument, rather than global.


add_action('publish_post', 'publish_post', 10, 2 );

function publish_post($post_id, $post) {

    // stuff
share|improve this answer

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.