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?
1 comment
Comments are closed.
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 useget_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:
wp_check_for_changed_slugs()
get_post_meta()