REIGN

9 min read · 1,798 words

Can You Undelete a WordPress Category? What to Do

Recovering a deleted WordPress category

No, WordPress cannot undelete a category. Categories have no trash, so deleting one is permanent. Posts that were only in that category move to your default category, and the category itself is gone. You can get the structure back by restoring a backup, or by recreating the category with the same name and slug and putting the posts back in it.

This guide explains exactly what a delete does, how to choose a recovery route, and how to stop it happening again.

What happens when you delete a category

Posts, pages and custom post types have a Trash. Taxonomy terms, including categories and tags, do not. When you click Delete on the Categories screen, WordPress removes the term straight away. According to the WordPress user manual:

  • Posts that were in the deleted category and in no other are assigned to the default category.
  • Posts that were also in other categories keep those other categories and are left alone.
  • The default category cannot be deleted. You can rename it and change its slug, and you can pick a different default under Settings > Writing.
  • Your posts are not deleted. Only the label connecting them to that category is removed.

Two more things follow from how WordPress stores terms. If the deleted category had child categories, WordPress moves them up so they take the deleted category’s parent. And because the connection between each post and the category is removed, WordPress keeps no list of which posts used to belong. Post revisions do not help here either, because they track content, not category assignments.

Check what you actually lost

Before you pick a recovery route, spend two minutes measuring the damage.

  1. Go to Posts > Categories and confirm the category is really gone. Check the search box, since it may only have been renamed or moved under another parent.
  2. Open Posts > All Posts and filter by your default category, usually Uncategorized. Posts that were only in the deleted category are now listed there.
  3. Note anything that referenced the category: menu items, widgets, category-specific templates, shortcodes, plugin settings and page builder queries. These stored the old ID, which will not come back.

If the posts in the default category are few and you remember where they belong, the manual route below is the fastest. If you cannot tell which posts were in the category, a backup is the only reliable source.

Route 1: restore from a backup

A backup taken before the deletion contains the term and every post-to-category link. This is the only route that restores the exact original data. You have two ways to use it.

Restore the whole site

This is simple but it rolls back everything, including posts, comments and orders created since the backup. Use it only on a quiet site or when the deletion happened minutes ago. Many hosts keep daily backups you can restore from the hosting panel. Backup plugins also let you restore the database on its own.

Restore to a staging copy and move the data across

This is the safer choice on a live site.

  1. Restore the backup to a staging site or a local copy.
  2. Open the Categories screen there and note the category’s name, slug, description and parent.
  3. List the posts that used it. With WP-CLI on the staging copy you can run wp post list --cat=ID --fields=ID,post_title, where ID is the category’s term ID (example code).
  4. On the live site, recreate the category (Route 2) and assign those posts to it.

Take a fresh backup of the live site before you change anything, and keep it until you have checked the result.

Route 2: recreate the category with the same slug

If you remember the name, this takes a minute and restores URLs.

  1. Go to Posts > Categories.
  2. Enter the original Name.
  3. Enter the original Slug exactly. The slug builds the archive URL, so the same slug brings back the old category link, for example /category/news/.
  4. Set the Parent and Description if the category had them, then click Add New Category.

Be clear about what you get back. The new category is a new term with a new ID. Anything stored by ID, such as a menu item, a widget or a plugin setting, still points at the deleted one and needs to be reselected. Anything that worked by slug, including the public URL, works again.

The same step with WP-CLI, if you use it (example code):

wp term create category "News" --slug=news

Route 3: put the posts back in the category

With the category recreated, assign posts to it.

For a handful of posts

Open each post, tick the category in the sidebar, and update. Or use Quick Edit on the Posts list to tick the category without opening the editor.

For many posts

  1. Go to Posts > All Posts and filter the list so it shows only the posts that belong in the category, for example by default category, date range or tag.
  2. Tick the posts, choose Edit from the Bulk actions menu and click Apply.
  3. Tick the category in the Bulk Edit panel and click Update.

Bulk Edit adds the category to the selected posts. The posts keep their other categories, so check whether you also want to remove the default category from them.

For a very large site

On a site with thousands of posts, clicking through lists is slow and error-prone. Use WP-CLI to add a term to a post by ID (example code):

wp post term add 123 category news

Feed it a list of post IDs from your backup in a loop. Try it on a few posts first, and make sure you have a database backup before you run it on all of them.

Special cases

Custom taxonomies and product categories

Everything above applies to any taxonomy, not just post categories. Tags, WooCommerce product categories and the custom taxonomies added by directory, events or course plugins have no trash either. Products without a category fall back to the default product category. If the taxonomy has extra data attached, such as a category image, an icon or an SEO title, that term meta is deleted with the term. Restoring from a backup is the only way to recover it. Recreating the category gives you a blank one, so you will need to upload the image again.

Child categories

If you delete a parent, its children are not deleted. They move up one level. After recovery, recreate the parent first, then edit each child and set its Parent again. Leaving this for later is how a tidy tree ends up flat.

Auto-assigned categories

Some plugins and imports assign categories by rule, for example a feed importer or a form that publishes posts. If one of those rules referenced the deleted category, new posts will keep landing in the default category until you update the rule.

A short recovery checklist

  1. Stop deleting. Do not clear more categories until you know what you need back.
  2. Take a fresh backup of the current state, so you can undo your recovery work.
  3. Find the most recent backup from before the deletion and note its date.
  4. Recover the name, slug, parent and description, from memory or from the backup.
  5. Recreate the category, matching the slug exactly.
  6. Reassign posts, in bulk where you can.
  7. Reselect the new category in menus, widgets and plugin settings.
  8. Reload the category archive on the front end and clear every cache layer.

Redirects, SEO and the public side

Deleting a category removes its archive page. Anyone following an old link, and any search engine that indexed the page, gets a 404 until you recreate it. If you restore the category with the same slug, the URL works again and you need nothing more. If you decided not to bring it back, set up a 301 redirect from the old archive URL to the nearest related category or page. A redirect plugin or your SEO plugin’s redirect feature does this without code.

Also check any sitemap and internal links that pointed at the old archive, and clear your caching plugin so visitors do not see a stale version of the category page.

How to avoid deleting a category by mistake

  • Keep automatic backups. Daily database backups kept for a week or two turn this problem into a ten-minute fix. Our hosting guide covers what to ask a host about backups.
  • Merge instead of delete. To retire a category, bulk-edit its posts into another category first, then delete the empty one.
  • Limit who can manage categories. The Editor and Administrator roles can delete terms by default. Give contributors and authors the lower roles unless they need more.
  • Take a backup before any cleanup. Reorganizing dozens of categories is exactly when a wrong click happens.
  • Write down your structure. A short list of category names, slugs and parents is a cheap insurance policy for a site with a large taxonomy.

Large sites feel this most. When a community or publication runs thousands of posts across many categories, a deleted term is slow to repair by hand. The scale page shows how Reign handles big sites, and the online community guide shows how to plan structure before you have thousands of posts to move.

Frequently asked questions

Can you undelete a WordPress category?

No, there is no trash or undo for categories. You can restore the category from a backup, or recreate it with the same slug and reassign its posts.

What happens to posts when I delete their category?

Posts that were only in that category move to the default category. Posts that were also in other categories keep those and are otherwise unchanged.

Will recreating the category bring back the old URL?

Yes, if you use the same slug. The archive URL comes back, but the category has a new ID, so menus, widgets and plugin settings that stored the old ID need to be reselected.

How do I find which posts were in the deleted category?

WordPress does not record it. Restore a backup to a staging copy and list the posts that used the category there, or check the default category for posts you recognize.

Can I delete the default category?

No. WordPress does not allow it. You can rename it, change its slug, or choose a different default category under Settings > Writing.

Do deleted categories go to the trash?

No. The Trash applies to posts, pages and media. Categories and tags are removed immediately.

Are the posts deleted when I delete a category?

No. Only the category is removed. Your posts stay published and are reassigned as described above.

Next step

If you are planning a content-heavy site, see how categories, members and discussion fit together in the Reign demos, then follow the community build guide to set up your own.

Reading
9 min · 1,798 words
Published
Sep 23, 2024
wbcomteam
Reign contributor

Writing about WordPress communities, BuddyPress, BuddyBoss, LMS plugins, and the business of paid communities.

Keep reading

More from the Reign blog

Browse all posts on community, WordPress, BuddyPress and the studio of plugins behind Reign.

What customers say on Trustpilot

Swift and expert coding!

Swift and expert coding by Kerit to apply a personalised display adjustment on the Reign Theme for a media plugin that was not fully supported at the moment.

RussellGB