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.

Is it possible to run a function every time a post is deleted. The function has to be run when the post is deleted from the admin or by the wp_delete_post() function.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Yes, by adding an action to the before_delete_post, delete_post, or deleted_post actions.

share|improve this answer
    
I was wondering how i could get the post id of the post being deleted. additionally, would this still work if multiple posts are deleted? –  shammer Jan 8 '12 at 9:01
1  
@shammer the post id is passed to your function, see the code sample on the delete_post page above. not sure how it behaves when multiple posts are deleted, I assume the action is triggered multiple times. –  Milo Jan 8 '12 at 16:28

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.