Support › General › Image Advanced field "Force delete" option doesn't workResolved
When I delete a post that has Image Advanced filed, attached image won't be deleted.
This might be compatibility problem with WPML.(not sure)
Actually disabling WPML doesn't affect the problem.
The option 'force_delete' => true is to delete the media file when removing it from the post meta (list images of image_advanced field). See my screen record for more information https://share.getcloudapp.com/v1u4Z8BD.
'force_delete' => true
As I mentioned, Force delete is enabled in Metabox Builder.
I also use the Meta Box Builder on the screen record. The documentation also notes about this setting:
force_delete Whether or not delete the images from Media Library when deleting them from post meta. true or false (default).
Delete the image from the list of the field which is created by Meta Box - post meta, not delete the image when deleting the post.
Is there a way to delete attached images when a post is deleted?
Actually, after deleting a post, the post meta is still stored in the database. So I think you should:
1. Delete the attachment (image).
2. Delete the post meta.
The action hook before_delete_post will help you to achieve the goal.
Refer to this topic: https://wordpress.stackexchange.com/questions/134894/correctly-delete-posts-with-meta-and-attachments
and some WP functions: