Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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);
share|improve this answer
    
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 '12 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 '12 at 18:27
add comment

Your Answer

 
discard

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.