I built a plugin for wordpress with custom post types and somewhere along the line I realized that I had to rebuild the way slugs are generated. Originally, I had the cpt making default slugs like new-post-1, new-post-2, etc. I realized this was silly and rewrote the naming convention to create a slug from the post title like it should be. The only issue I have now is that I want to have all the old posts I entered into wordpress use the new naming convention. Is there a function or a way to tell wordpress to rebuild/regenerate the slugs for a particular custom post type.
I found this plugin: http://wordpress.org/plugins/re-slug/
But.. it does not work for cpts
Thanks for the help.
I also created a similar approach as was mentioned by @sri, however using $wpdb vs wp_update_post should be more performant and configurable.
source: https://gist.github.com/codearachnid/9243595
The re-slug plugin can be fixed to work with WordPress 4 and up. Edit line 13 of re-slug.php to read:
$return = str_replace('Edit</button>', 'Edit</button> <button type="button" id="re-slug" class="edit-slug button button-small hide-if-no-js" style="display:inherit;"><a href="#re-slug">Re-slug</a></button>', $return);
My fix isn’t very clean but for a first pass it works well enough, including for custom post types. The button is added which allows for the current post to be reslugged with whatever is in the Title field.
This is the only solution I’ve been able to find for a re-slug for a single post.