add_action( 'before_delete_post', 'nxw_delete_post_attachment' ); function nxw_delete_post_attachment( $post_id ) { $args = array( 'numberposts' => -1, 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_status' => 'any', 'post_mime_type' => 'image' ); $attachments = get_children( $args ); foreach( $attachments as $attachment ) { wp_delete_attachment( $attachment->ID, true ); } } 記述後に記事の
![WordPress:記事の削除と同時に使用されている画像も削除する方法 - NxWorld](https://cdn-ak-scissors.b.st-hatena.com/image/square/aab78f90e2c72d2f55ba59d254868698da208963/height=288;version=1;width=512/https%3A%2F%2Fwww.nxworld.net%2Fthumbnail%2Fwordpress.png)