From 12eb2c5a718081fa5a0bb16eb42bb03c3f1c8804 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sun, 18 Oct 2009 13:58:44 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wp-includes/post.php b/wp-includes/post.php index 5f854935d7..351a325409 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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 ) ));