WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
@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


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.