I created a custom WordPress plug-in that hooks onto 'save_post" using add_filter(). I need to do something with the post titles and whenever a user changes the title, my plug-in cannot get the new title until the post is updated a second time (without changing the title in the admin a second time).

For example, I have a post named "WordPress Rocks". I change it to "WordPress is Cool", but my plug-in shows the title as being "WordPress Rocks" using get_the_title($post_id) when updating the post. I go back and make a second update to the post, this time without changing the title. This next time, get_the_title($post_id) shows the title is "WordPress is Cool".

How can I grab the updated title (if it's changed) as soon as the post is updated?

1 Answer 1


The second argument of the save_post action contains the post data:

do_action('save_post', $post_ID, $post);

You can also hook post_updated which will let you easily compare the before/after data:

do_action( 'post_updated', $post_ID, $post_after, $post_before);
  • Thanks for the response! I'm confused about where to run do_action(). Here is how I'm calling save_post: public function __construct() { add_filter("save_post", array($this, "runCode")); }
    – user1462
    Dec 7, 2012 at 18:21
  • sorry, these bits are from core source where the actions you're hooking are actually called. see the $accepted_args argument of add_action to access the additional passed data. also note save_post is an action, not a filter!
    – Milo
    Dec 7, 2012 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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