1

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.

1 Answer 1

4

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

2
  • 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, 2012 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, 2012 at 16:28

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.