3

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.

1

The post_updated action gives you both old and new values as arguments before the new values are saved:

do_action( 'post_updated', $post_ID, $post_after, $post_before );
  • Exactly what I was looking for. Thank you very much. – Zoran Ilievski Apr 5 '18 at 6:35

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.