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

Basically I have so many images associated with custom post type that I need to be able to safely delete all related media on removal from trash.

Is there a safe way of doing this?

share|improve this question
up vote 1 down vote accepted

Is your post to image association custom?

If not attachments should be automatically deleted by Wordpess. If the connection is custom, Wordpress provides a delete_post action that fires before and after a post is deleted, it will pass the ID of the post so you can use that to delete all custom content associated with it.

share|improve this answer

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.