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
This commit is contained in:
markjaquith 2009-10-18 13:58:44 +00:00
parent 5f9ac8a5fd
commit 529cc9244b
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 ) ));