I have made a wordpress plugin to find and replace keywords in database, where admin provides keywords to find and to replace, and then the MYSQL query does the changes in DB.
But all I want to know the way to avoid the duplicate slugs.
For example :
As if there are two posts with following slugs:
- firstpost
- secondpost
and then admin runs the query and wants to replace "second" with "first". then the result will be:
update wp_posts set `post_name` = replace(post_name, 'second','first') where post_type='post' - firstpost
- firstpost
Is there a way to keep the slugs unique ?
1062. Put the query inside atry-catchblock and inside the catch you can then check if the error code equals 1062.