Getting Post details when post is published

The function is wp_insert_post(), and as you can see there are some hooks you can use to modify data. wp_insert_post_data is a filter that gets all data right before it will be inserted into the database, so you modify it there and don’t need to do anything to get it saved. At the end of the function you can see the save_post action and its equivalent wp_insert_post, which are more appropriate if you want to do something (instead of change something).

These functions are fired when a post is saved, not only when it is published. For the publish action, look at wp_transition_post_status(), which has three hooks:

  • transition_post_status, called with the new and old statuses, and the post data
  • {$old_status}_to_{$new_status}, like draft_to_publish, called with the post data
  • {$new_status}_{$post->post_type}, like publish_page, called with the post ID and post data