0

I'd like to get the original value of the $post on the save_post action. This way I can detect changes, and only do specific actions if the post content/title was changed.

Is this possible?

  • 1
    I think save_post hook is too late as the post is already saved. I currently don't have the time, but there should be hooks that fire earlier, check the source code of wp_update_post() – kero Jan 10 at 9:57
0

This is the solution:

add_action('pre_post_update', function($post_id, $post_data) {
    global $original_post;

    $original_post = get_post($post_id);
}, 10, 2);

add_action( 'save_post_', function($post_id, $post, $update) {
    global $original_post;

    $original_post->post_title; // original post title
    $post->post_title; // new post title
}, 10, 3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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