From 529cc9244b471734b137e4c8350b99e5753798ba Mon Sep 17 00:00:00 2001 From: markjaquith 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: http://svn.automattic.com/wordpress/trunk@12054 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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 ) ));