When trashing a post, all comments associated with this post get the status "post-trashed". They do not end up in the trash bin.

In my theme the author gets a point for posting a post or a comment. Subsequently I also want to deduct a point when the posts or comments is trashed.

Both of these functions works excellent. The problem arise when I trash a post. I want the associated comments to also be affected, and have one point reduced.

This function: http://de.wpseek.com/wp_trash_post_comments/ seems to be the culprit. So I think the best solution is to either somehow force the "post_comments" to be sent into the actual trash bin, or somehow incorporate an action to the above function to also remove a point when trashing "post_comments". (it would be important that there is no conflict with trash_comment, so the action somehow doesn't get called twice, and reduces two point for one comment being trashed).

Any ideas?

1 Answer 1


There's an action called trashed_post_comments that runs right after the comments are set to post-trashed status. You could hook into that:

add_action( 'trashed_post_comments', 'wpse134528_really_trash_comments' );
function wpse134528_really_trash_comments( $post_id ) {
    $args = array( 
        'post_id' => $post_id,
        'status' => 'post-trashed',
    $comments = get_comments( $args );
    foreach( $comments as $comment ) {
        wp_trash_comment( $comment->comment_id );


Hopefully this helps, though I'm not sure I understand why comments with their status set to post-trashed would be messing up your theme...

  • Thanks, but I can't seem to get that function to work. My theme is using a point system. Author get points when posting posts and comments. And when the posts or comments are removed (thrown in the trash), the user get one point deducted (this is done with a update_user_meta function along with the actions wp_trash_post and trash_comment). The problem is when I trash a post, the attached comments are not affected because they get the post-trashed status. At least I think this is the reason why it doesnt work.
    – dkl
    Commented Feb 14, 2014 at 15:11
  • You might want to update your question with all the details.
    – Pat J
    Commented Feb 14, 2014 at 15:29
  • I've updated the question. I'd appreciate if you have a look at it once more!
    – dkl
    Commented Feb 15, 2014 at 9:06
  • Any ideas, Pat J?
    – dkl
    Commented Feb 16, 2014 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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