📅  最后修改于: 2022-03-11 14:55:20.443000             🧑  作者: Mango
add_action( 'before_delete_post', 'wps_remove_attachment_with_post', 10 );
function wps_remove_attachment_with_post( $post_id ) {
/** @var WP_Post[] $images */
$images = get_attached_media( 'image', $post_id );
foreach ( $images as $image ) {
wp_delete_attachment( $image->ID, true );
}
}