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.

When deleting a post, all comments associated with this post get the status "post-trashed". I'm searching a hook for this event.

Tried these one without success: comment_approved_to_post-trashed comment_approved_to_trash

share|improve this question
add comment

2 Answers

There are few other hooks to manipulated the trashed comment.

  1. 'save_post': called after post is saved. You can check status of the post and manipulate its comment accordingly.
  2. 'trashed_comment': called after comment is moved to trash status.
  3. 'transition_comment_status': called whenever comment status is changed.

There are probably few others too. But, it depends what you want to do with the trashed comments.

share|improve this answer
    
the second hook won't trigger when deleting a post, because the comment is actually not trashed (not visisble in the trash or anywhere else), it only gets the status "post-trashed" in the database. I will try it with the third hook. Which parameters will I get with that hook? I need at least the comment_ID and the old+new status. –  Chris Dec 13 '12 at 13:20
1  
Found it: wp_transition_comment_status( $new_status, $old_status, $comment ) –  Chris Dec 13 '12 at 13:21
add comment

Sadly your hook didn't trigger when deleting a post. But I just looked into the wordpress code and found the right hook:

* @uses do_action() on 'trashed_post_comments' after trashing

in the function

wp_trash_post_comments()

And then just add the action like that:

add_action('trashed_post_comments', 'sp_trashed_post_comments', 10, 2);
...
function sp_trashed_post_comments($postID, $statuses) {
    $commentIDs = array_keys($statuses);
    print_r($commentIDs); // echoes all commentIDs associated with the deleted post
}
share|improve this answer
add comment

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.