Get old values for post before saving new ones

I’m using the save_post hook to do some additional logic after a post has been saved.

However I need to find a way of getting the old values of the post, specifically in my case the slug/handle aka post_name.

Tried using the wp_insert_post_data filter to catch the post and add the old slug as an additional field pre save but that doesn’t seem to work.

TL;DR want to achieve something like this:

public function post_sync( $post_id, $post, $update ) {

$post_new_handle = $post->post_name;
$post_old_handle = $post->post_old_name;

if($post_new_handle !== $post_old_handle) {
//additional logic
}

//additional logic

}

Any way of achieving this?
Thanks.

Read more here:: Get old values for post before saving new ones

Leave a Reply

Your email address will not be published. Required fields are marked *