WP does not do this by default since there is no guarantee that attachment isn’t still being used by some other post.
Basic logic would be to hook into delete_post
, query for child attachments and run wp_delete_attachment()
on each.
I did quick search in plugin repository and came up with tiny plugin that does just that (seems unmaintained so test before use) – Post Data Delete Advanced.
Related Posts:
- Turn a URL into an Attachment / Post ID
- Delete Associated Media Upon Page Deletion
- Is it possible to Schedule Attachments in WordPress?
- what types of order can I pass to get_posts() via orderby?
- Find the post an attachment is attached to
- media_handle_upload for local files?
- How do I detach images from posts?
- Use an attachment in multiple posts
- delete post also attachments
- Replacing all attachment links in post with media file link
- Get post id by attachment id?
- How can I export WordPress posts’ attachments?
- How to remove images from showing in a post with the_content()?
- How do I create Comma Separated list of attached image ids?
- Get post embedded image caption
- Limit amount of results returned
- post_parent is 0 when uploading new files
- Easy way to delete 70k posts and attached media?
- How to access featured image?
- Load post attached images on a single page site with fancybox
- Insert woocommerce products programmatically with featured image and gallery
- Add the description field on the attached media
- Set size for attachments
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- Get all attachment by post excluding featured and content inside
- Prevent Delete Attachment by URL or When Submit
- Posts and Attachments with “Published” status in Search
- Get attachments for posts that belongs to a specific category
- Automatically attach image to post if they have the same title
- Get Image tag from content of post
- Can’t update old posts 3.5.2
- How would one change the default url structure of attachments?
- Get attachments only for this post
- Upload attachment from external site
- Reinstall WordPress while keeping attachments
- Get images from the post
- How To Download WordPress Audio Attachments
- How to get the next and previous image title from attachment or gallery?
- All images on one line for each post
- How do I assign an attachment to a post using only the REST API?
- Unable to delete attached file from folder programmatically
- How to convert attachment pages to Posts?
- Get post attachment with post id
- Delete attached images from posts
- Unable to get all the Posts Attachments
- Add in the url attachment loop the wp_link_pages of the post
- Stop images from being displayed on the front-end of the site
- How to get images only attached from edit post page
- How to prevent people from seeing an attachment to a scheduled post that’s released in future?
- How can I get a comment ID on Submit?
- Bulk Attach Or Insert Media To Post Without Opening Post Editor
- Post Attachment missing head (stylesheets/js/what-not)
- Create post from form with image
- Get Video Attachment to post
- how to edit attachments?
- Broken images after importing posts and opening in Gutenberg
- Print Current Post Index number within Loop
- Front-End Post Submission
- How To Disable (or Remove) “All Posts, Published, and Trash” in Dashboard Posts
- Different number of posts in each category
- Trying to get property of non-object when using $post->post_parent
- How to change the layout and styling of posts according to their category in WordPress?
- Sort wp post title with alphabetically and numerically?
- How to get new post URL?
- Different amount of posts on homepage than paged pages
- The correct way to call posts with ajax
- ‘transition_post_status’ only fires when pressing “Add New”
- I want to show category in the post title , how can I do
- Split WP_POST table based on post types
- How to re-post an old post?
- Multiple loops are not reset
- Polylang post_translations key [closed]
- Do action on publish or update?
- How to get posts and comments amount per hour, per year and per month?
- How to make only posts show date
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- Let both the admin and post author update comment meta
- WordPress Query Posts From Category Post on Static Page
- add external project to web site wordpress on production
- How to remove text and retain in caption image using the_content function
- alternative to wp_link_pages() that only shows link to last page
- How to exclude the word “class” from being matched in search?
- Count user posts and store the number for later use
- display jumps to the bottom, dosnt start at the top?
- How to determine if a post was last edited in the Visual Editor
- “Blog pages show at most” in setting not working
- What permissions does a role need for the user to be assigned as the author of a post?
- Countrywise Post View
- Scrollbar disappear in post window
- Compare date of user’s last posts
- Only get post_id [duplicate]
- Disable `create_post` for built-in post type
- how to create other sizes of original image in one go wordpress uploads
- Post are not showing up
- Can’t seem to replicate permalink structure for localhost development site
- Newly created category does not show category
- WordPress Custom Theme: My site shows the same posts on Page 1 and Page 2 and so on [duplicate]
- WordPress post enumeration
- Output number of WordPress posts remaining until a post milestone is reached