Created
January 23, 2018 11:31
-
-
Save trueqap/fe5c92a7b6d9b8625636c6c09f0e0113 to your computer and use it in GitHub Desktop.
Delete WooCommerce products with images (attachment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function delete_associated_media( $id ) { | |
$media = get_children( array( | |
'post_parent' => $id, | |
'post_type' => 'attachment' | |
) ); | |
if( empty( $media ) ) { | |
return; | |
} | |
foreach( $media as $file ) { | |
wp_delete_attachment( $file->ID ); | |
} | |
} | |
add_action( 'before_delete_post', 'delete_associated_media' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment