Determining Slug Before and After Edit

If I were to edit a post or a page, how would I determine what the slug was before the edit, and again afterwards to compare them and see if it was changed? Also, would the same method work for any Custom Post Types created, or is that done differently?

Related posts

1 comment

  1. If the post/page was previously published, and you changed the slug when you edited the page, the old slug gets put into the post meta table with the name _wp_old_slug. So you can use get_post_meta( $post->ID, '_wp_old_slug', $single = false ); to retrieve the former slug(s). I see no reason this wouldn’t work with CPTs, as they’re just a special type of post.

    Reference:

Comments are closed.