I have a custom post type called task. I want the slug of each task to be an id, rather than use the entered title. I’ve modified the code from this SO question “How to customize this automatic slug shortener with an overrwrite function” as such:
add_filter('name_save_pre', array(__CLASS__, 'change_task_slug_to_id'));
static function change_task_slug_to_id($slug)
{
// should prevent slug from being continually modified
if ($slug) return $slug;
return date('U');
}
However every time I add a new task, the slug is created with “-2” appended to it:
How can I prevent WordPress from re-modifying the slug, and appending the “-2”?