I have a custom db table that stores additional post data and I need to delete posts from my custom table when the original post is deleted.

Will WP fire the delete_post action below and run my_function when WP "automatically" deletes posts that have been trashed?

add_action( 'delete_post', 'my_function');

I can set up an option to manually purge my custom table if needed but I would prefer it to happen automatically.

1 Answer 1


Short answer

Yes, it does ;)

Long answer

The function that is used to empty the trash/remove trashed posts is called wp_scheduled_delete. When you'll take a look at it's code, you'll see, that it uses wp_delete_post to delete the posts and inside wp_delete_post the action delete_post is run as you can see here.

Your Answer

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

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