Delete post thumbnail relationships for deleted attachments. props scribu. see #10928

git-svn-id: https://develop.svn.wordpress.org/trunk@12054 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2009-10-18 13:58:44 +00:00
parent 94a2054bf5
commit 12eb2c5a71
1 changed files with 2 additions and 0 deletions

View File

@ -2710,6 +2710,8 @@ function wp_delete_attachment($post_id) {
/** @todo Delete for pluggable post taxonomies too */
wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND meta_value = %d", $post_id ));
$commentids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
do_action( 'delete_comment', $commentids );
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_ID IN(%s)", implode( ',', $commentids ) ));