As it is now, when I trash a post, the related comments get deleted at once. Is this standard?

Instead I'd like them to be moved to the trash bin, when I trash the post.

How can I achieve this? I can't seem to find a solution.


Well, this is partly true and partly false.

When you trash a post, everything that is tied to it is also trashed. This means, if you untrash the post, the comments etc. are untrashed as well.

However, comments and other stuff is not handled as if they were trashed directly (i.e., on the Comments page in your WordPress Admin). If you directly trash a comment, it shows up in the comments trash bin.

The reason for this is: If comments of recently trashed posts appear in the comments trash bin, you can easily untrash them. But what if not just the comment had been trashed but the related post (and so the comment)? Then you either had to automatically untrash the post as well, or don't provide any means to untrash a comment that was trashed due to its post being trashed.

In short: if you just trash a post, none of the tied-to-it data gets deleted—it gets trashed as well.

I hope this makes sense.

  • There seems to be some sort of a conflict here. When I trash the post, the comments get removed from a backend, as if it was deleted (it's not shown in the actual bin). But when I restore the post the comment also gets restored, even though it's not visible in the bin. Is that what you mean? Is it suppose to work like that?
    – dkl
    Feb 13 '14 at 8:47
  • Yes, exactly. That is what I tried to explain. The comments don't get deleted, but you also don't can see them in the comment trash bin (and hence untrash them). This is by design (and absolutely makes sense). Another possible way of handling this could be: show comments in the comment trash bin, but don't allow them to be untrashed if the related post is trashed. But that's not as it's done right now...
    – tfrommen
    Feb 13 '14 at 8:50
  • Hm, but this is a problem for me. I have a theme where the users gets a point for posting comments and posts. So when I trash the post, I also want to trash the comments that are attached, and deduct a point when the comment is trashed. Is this not possible? This function, is it called something? (the function that sends comments into a pre-trash bin) ?
    – dkl
    Feb 13 '14 at 8:57
  • Basically, I have a function that deducts a point when I manually trash the comment. It works fine. But this does not work when I trash a post, and wanting to trash the related comments. Obviously this is due to the system that you just explained.
    – dkl
    Feb 13 '14 at 9:02
  • 1
    Well, the comments are trashed in wp_trash_post_comments, where the action 'trash_post_comments' is called (providing the post ID as parameter). This is where you could hook into, then fetch all the comments (like it is done in the very file I linked to) and deduct points for each and every comment. But that is another question. If you have problems doing this, please start another topic. Thanks.
    – tfrommen
    Feb 13 '14 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.