Iv’e been searching for a while now and my search so far has been very unsuccessful. I’m looking for a function that deletes the featured image and post when clicking delete post on the posts page in the dashboard.
What I would like: Clicking delete on a post deletes instantly along with it’s featured image instead of being moved to the “trash”.
Sorry I’m not a pro developer, I’m a noob and just starting out. Any help would be great. Thank you!
In any case, wp_delete_attachment requires attachment_id and not post_id. saved you half an hour 😉
You could use add_action hook into delete_post function, and run a function that will deelte the featred image after getting it by the post id.
https://codex.wordpress.org/Plugin_API/Action_Reference/delete_post
You can attach the WordPress function for “before deleting a post”…
So under your theme’s function.php file:
This will delete all the attachments (images) on that page being removed. You will have to tweak it just to be the featured image instead, however it might help you figure it out.
You can use
wp_trash_post
action hook, it runs onn post, page, or custom post type is about to be trashed