Created
December 1, 2013 21:05
-
-
Save Boztown/7740769 to your computer and use it in GitHub Desktop.
Wordpress: Delete attachments after a custom post type is deleted.
This file contains hidden or 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
function handle_delete_listing( $post_id ) | |
{ | |
$cargs = array( | |
'post_type' => 'attachment', | |
'post_parent' => $post_id | |
); | |
$attachments = get_children($cargs); | |
if ($attachments) { | |
foreach ($attachments as $attachment) { | |
wp_delete_attachment( $attachment->ID, true ); | |
} | |
} | |
} | |
add_action( 'before_delete_post', 'handle_delete_listing' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment