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.

Leave a Reply

Your email address will not be published. Required fields are marked *