I have thousands of posts on my site which are created automatically. Some of them have duplicated titles. I'd like to add some keywords to their slugs, so URLs like
domain.com/post-title/
domain.com/post-title-2/
become
domain.com/post-title-some-keywords/
domain.com/post-title-2-some-other-keywords/
I can easily do that using wp_update_post
function and normally a URL domain.com/post-title-2/
will automatically redirect to domain.com/post-title-2-some-other-keywords/
. However, if I add a new post with the same title, it's URL will be domain.com/post-title-2/
(since old one doesn't exist anymore) and that redirection won't work anymore.
How to avoid this?
I want a new post to have the URL domain.com/post-title-3/
, even though domain.com/post-title-2/
is available. Is there any other option, besides saving old slugs in a separate table?
Update: I'm aware that old slugs are kept in wp_postmeta
, but that doesn't help with the redirection problem.