Fixing the “-2” in WordPress Category Slugs

I was asked to look at a WordPress site that needed help with their pretty URLs. Most of them worked just fine, but a few of the categories had “-2” at the end of them, and they wanted that removed. The “-2” normally signifies that it’s a duplicate, but they did not have any duplicate categories. So what was causing the “-2”? I double-checked the admin panel, and they were correct that there were no duplicate categories. I then took a look at the database. The categories are contained in the wp_terms table. Sure enough, there were duplicates in the database table that were not showing up in the admin panel.

I double-checked which record was which, and when I was sure I knew which record was the old one (the one not showing up in the admin panel), I deleted that row. I had seen recommendations for deleting all instances in the database and recreating the categories from scratch, but I did not want to do that because there were so many posts tied to these categories, and I didn’t want to risk messing up those connections. Instead, I just deleted the old record that was preventing the new one from being edited.

Then, I logged into the admin panel and went into the Categories section. I clicked “Edit” (or you can click “Quick Edit”) and modified the slug for the category to remove the “-2”. I then clicked “Update”, and the category URL no longer contained “-2”.