# How can I delete or undelete topics?

**URL:** https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700
**Category:** Support
**Created:** [Mars 29, 2016, 8:25 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700 "2016-03-29T08:25:18Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Mars 29, 2016, 8:25 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/1 "2016-03-29T08:25:18Z")

</div>

I used the embedded feature to tie together a blog with my forum. While testing I deleted all those posts. Now that I’m trying to re-create the integration I realised that deleting posts just don’t actually delete them, it just hides them. So, now the integration is broken because users don’t have access to them.

How can I:

- _Really_ delete the topics so that the embedding can re-create them?
- OR find a list of all the “deleted” posts so that I can undelete them?

(C.f. [Embed Discourse comments on another website via Javascript - #115](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963/115))

---

<div class="post-metadata">

### Author: ![zainab](https://avatars.discourse-cdn.com/v4/letter/z/258eb7/32.png) [@zainab](https://meta.discourse.org/u/zainab)
#### Post date: [Mars 29, 2016, 9:40 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/2 "2016-03-29T09:40:40Z")

</div>

If all the posts you deleted was created by you, then under your profile you can see what posts you deleted and then you can undo the delete

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [Mars 29, 2016, 9:58 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/3 "2016-03-29T09:58:11Z")

</div>

By site setting the posts you deleted are only hidden (to all except admins) for 24 h.

In this period you can undelete all of them. After 24 h they are deleted forever.

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Mars 29, 2016, 10:24 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/4 "2016-03-29T10:24:24Z")

</div>

@Trash: Thanks, but this setting doesn’t apply to topics, only to posts. In any case, I don’t think it even _really_ deletes them from the database, which is what I’m asking for.

@zee: Where is this? I looked under [http://www.example.com/users/my\_admin\_user/activity/topics](http://www.example.com/users/my_admin_user/activity/topics) but I can’t find anything. (Though, again, I’m talking about topics not posts.)

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [Mars 29, 2016, 10:46 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/5 "2016-03-29T10:46:51Z")

</div>

> [@Trash](#):
>
> By site setting the posts you deleted are only hidden (to all except admins) for 24 h.

This site setting is unrelated – it only applies to posts deleted by the author, which will stick around as `(deleted by author, will be removed in 24 hours unless flagged)` for the specified time.

> [@alehandrof](#):
>
> Where is this? I looked under [http://www.example.com/users/my\_admin\_user/activity/topics](http://www.example.com/users/my_admin_user/activity/topics) but I can’t find anything.

Profiles with deleted topics once showed a red “notification” to staff members, but it seems to be gone. Maybe this was dropped when the Activity page was restructured (by @sam if I recall correctly).

You can definitely use the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) to find deleted topics, though.

* * *

And here’s how:

Run this query:

```sql
SELECT *
FROM topics
WHERE deleted_at is not NULL
AND archetype = 'regular'

```

Look through the list to find the topic, and memorize the ID.  
Then, visit `/t/<id>` in your Discourse install to view the topic. From there, you can easily restore the topic.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [Mars 29, 2016, 11:42 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/6 "2016-03-29T11:42:12Z")

</div>

As admin the posts you have deleted should be listed here:  
`http://www.example.com/users/{your-username-here}/deleted-posts`

This is linked from the top of your profile page, clicking the ![](https://global.discourse-cdn.com/meta/original/3X/5/f/5fc50ee11596e8e1658073ea9d9ca7ecc2fa2019.png) button will show something like this in the top left:  
 ![](https://global.discourse-cdn.com/meta/original/3X/6/e/6e38ac61168750b0e8a87951fe911a17d937b140.png)

Click “deleted posts” to see the posts you have deleted.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Mars 29, 2016, 12:28 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/7 "2016-03-29T12:28:52Z")

</div>

There is also the querystring (also works with category/latest page)

/latest?status=deleted

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Mars 29, 2016, 1:03 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/8 "2016-03-29T13:03:51Z")

</div>

@DeanMarkTaylor: thanks for pointing out this helpful, though well-hidden, feature. But it only lists posts, not topics.

The solutions that @fefrei and @cpradio suggested work fine, though the latter is simpler to use.

Unfortunately I can’t undelete topics at all. I have two admin accounts, the one that was used during embedding to create the topics in the first place ( `adminbot`) and my personal account (`alex`). I tried undeleting the topics with both accounts and neither works. The topics remain deleted.

**Is there a way to _really_ delete the topics?**

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Mars 29, 2016, 1:07 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/9 "2016-03-29T13:07:50Z")

</div>

This is risky, and I’d advise you wait until a Discourse Team member can provide better feedback, but something like this should work from the Rails console, so long as you know the topic ids you want to delete.

```plaintext
Topic.find(topic_id).destroy

```

---

<div class="post-metadata">

### Author: ![zainab](https://avatars.discourse-cdn.com/v4/letter/z/258eb7/32.png) [@zainab](https://meta.discourse.org/u/zainab)
#### Post date: [Mars 31, 2016, 7:05 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/10 "2016-03-31T19:05:40Z")

</div>

@alehandrof Sorry wasn’t online last few days, What I was talking about @DeanMarkTaylor posted a screen shot

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [Mars 31, 2016, 7:24 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/11 "2016-03-31T19:24:20Z")

</div>

I’m having trouble following as there at least 2 if not 3 issues being discussed.

In regards to Topics, in the context of deleting / undeleting topics Discourse considers the OP as the Topic. That is, the topic _is_ the first post.

In other words, if the first post is deleted (the trash can icon), the topic is deleted. Regardless of how many replies it might have.

Conversely, if the first post has been deleted, the “counter-clockwise circular arrow” icon can be used to undelete the OP, thus in effect undeleting the topic.

As far as “really” deleting a topic, as in removing all trace of it from the database. I don’t know, but I would strongly suggest this _not_ be attempted.

There is a lot of cross-indexing of tables and unless there is some type of DELETE CASCADE that I haven’t seen yet things could break in the most horrible way imaginable.

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Mars 31, 2016, 8:40 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/12 "2016-03-31T20:40:10Z")

</div>

@Mittineague: I’ve done a sloppy job of describing what the issue is. Let me try again. I’m usually better on the 2nd try.

I want to start embedding topics on a live site. Unfortunately, I already set up embedding in the past. While I was testing things, I deleted the topics that were thus created.

Problems:

- I am not able to undelete the embedded topics even with the account that created them. I undeleted two of them, but the rest refuse to be undeleted. No idea why.
- I am not able to totally remove the embedded topics from the database.

Either would work (and I would prefer the second), but neither does. So I’m stuck. Ideas?

Edit: revised for clarity

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [Avril 1, 2016, 12:07 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/13 "2016-04-01T00:07:16Z")

</div>

The downtime let me do some testing and watch a bit of the Build 2016 livestream

[http://www.sitepoint.com/build-2016/](http://www.sitepoint.com/build-2016/)

On my localhost a member created a topic and then - no replies had been made to it yet - a Moderator account deleted it.

To see it logged in as Admin I needed to go to  
`thesite/latest?status=deleted` to see it.

Once there I needed to use the topic admin wrench

 ![](https://global.discourse-cdn.com/meta/original/3X/4/3/436d58eafa6ee88217e0d3acc06bd75093a20fac.png)

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Avril 1, 2016, 11:44 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/14 "2016-04-01T11:44:47Z")

</div>

Thanks for taking the time to write that up. But I’ve gotten that far.

The problem is that the posts will fail to be undeleted.

This is what Discourse throws up in the console:

 ![](https://global.discourse-cdn.com/meta/original/3X/3/3/339c1d394b8b1a06f7e19f2657f571197e015be2.png)

Any help would be much appreciated.

Edit: this is in Chrome Incognito with the current user being the owner of topic.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Avril 1, 2016, 11:52 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/15 "2016-04-01T11:52:31Z")

</div>

Can you expand the PUT error and do you see anything related in [https://yourdiscoursesite.com/logs](https://yourdiscoursesite.com/logs)?

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Avril 1, 2016, 12:12 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/16 "2016-04-01T12:12:31Z")

</div>

Nope. Does anything else look interesting?

 ![](https://global.discourse-cdn.com/meta/original/3X/8/7/87d6f0acda15875ac86ee30740918d24f444ef13.png)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Avril 1, 2016, 12:17 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/17 "2016-04-01T12:17:08Z")

</div>

That is bizarre, as that should be generating something in the Admin \> Logs \> Error Logs (which is actually located at /logs). As that 500 Internal Server Error is an error on the backend.

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Avril 12, 2016, 6:03 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/18 "2016-04-12T18:03:39Z")

</div>

Continuing the discussion from [Embedding Discourse Comments via Javascript](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963/117):

> [@Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963/117):
>
> You will need to update the topic\_embeds table in this case. Discourse still has the relationship between the deleted topics ☹

@eviltrout Can you please elaborate a little bit? Other forum users have suggested I’ve stumbled into [a bug](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/14).

> [@Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963/117):
>
> I’ve actually not heard of someone wanting a private discourse but having embedded comments. Wouldn’t the vast majority of people never be able to see them?

Yes and it’s fine.

I work for a higher education consortium. The private Discourse is a forum for the members of that consortium (a few hundred users at present). The comments are for our public blog but on our site they’re only visible to members. I also plan to use the embedding system for other content as well. The idea is to allow members to quickly open a discussion on a blog post, an event, or other piece of content. That’s why, ideally, I wouldn’t want to create entries for all the new content.

P.S. The [original thread](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963/) was closed and I could not reply.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [Avril 18, 2016, 9:20 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/19 "2016-04-18T21:20:18Z")

</div>

> [@alehandrof](#):
>
> Can you please elaborate a little bit? Other forum users have suggested I’ve stumbled into a bug

I’m not sure if you’ve hit a bug or not, but I suspect it is related to the TopicEmbed table. Since you can’t recover the topics, I suspect you remove all the entries in the `topic_embeds` table via the database console, then let embedding recreate the topics.

> [@alehandrof](#):
>
> The idea is to allow members to quickly open a discussion on a blog post, an event, or other piece of content.

Just to be clear, you are aware that you can’t post via embedding right? It’s only for displaying. It’s usually meant to attract people to the forum content.

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [Avril 22, 2016, 6:44 UTC](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700/20 "2016-04-22T06:44:26Z")

</div>

> [@eviltrout](#):
>
> I suspect you remove all the entries in the topic\_embeds table via the database console, then let embedding recreate the topics.

I feel daft for asking, but I’m not able to find any documentation on how to do this. Any pointers?

> [@eviltrout](#):
>
> Just to be clear, you are aware that you can’t post via embedding right? It’s only for displaying. It’s usually meant to attract people to the forum content.

Yep. I realise that. That’s why I’m more interested in a gateway button like “Discuss in our forum”, that take the user to a new topic, populated with content from the site, or to an existing topic, if it’s already been created. (Because our Discourse is private anyway and only logged in users would be able to see the posts on the site.)

[Page suivante](https://meta.discourse.org/t/how-can-i-delete-or-undelete-topics/41700.md?page=2)
