Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer
    
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 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... –  t f Feb 13 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 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 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. –  t f Feb 13 at 9:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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