You need to use before_delete_post
action. As its already very late when delete_post
action is run. WordPress un-attach all the attachments before running delete_post
action. So when you run get_posts
in your delete_attachment
function there are no attachments found.
So you need to hook your function to before_delete_post
.
add_action('before_delete_post','abc_delete_attachment');