This guide provides instructions on how to bulk delete all topics within a category on a self-hosted Discourse instance.
Required user level: System Administrator
SSH access to your server is required
Removing all topics from a category can be necessary for various reasons, such as reorganizing content or clearing outdated discussions. This guide walks you through the steps to accomplish this task safely on a self-hosted Discourse server.
This is a destructive action. Make sure to back up your forum before continuing
Steps to delete topics in a category
- Identify the category slug: This is the name used in the category’s URL.
- Access your server: Use SSH to log into your server.
ssh username@your-server.com
- Navigate to the Discourse directory:
cd /var/discourse
- Enter the Discourse application:
./launcher enter app
-
Execute the deletion command: Replace
"mycategory"
with your category’s slug.
rake destroy:topics["mycategory"]
This process may take time depending on the number of topics.
Deleting topics in subcategories
To delete topics in a subcategory, include the parent category’s slug in your command. For example:
rake destroy:topics["childcategory","parentcategory"]
Delete all topics in all categories
This action will clear all topics from every category!
rake destroy:topics_all_categories
Common Questions
How long Discourse stores deleted topics? I can still access topics with direct link.
The topics remain in the database forever. Only staff will still be able to see deleted topics
How can I delete topics from the database?
Topics cannot be deleted from the database.
Is it be possible to restrict the topic deletion to a time period (between two dates)?
You’d need do it from the rails consoles, a command similar to the following should work:
Topic.where("created_at.....").destroy_all
Is category ID the position on the categories page?
The category ID is what you’d see if you do
rake categories:list
Additional Information
For more information about other administrative operations please see:
Last edited by @SaraDev 2024-11-07T20:50:52Z
Check document
Perform check on document: