Ticket #2681: orphan_attachments.patch

File orphan_attachments.patch, 624 bytes (added by ryanscheuermann, 7 years ago)

orphan attachments after deleting post (update post_parent = 0)

  • functions-post.php

     
    572572        if ( 'page' == $post->post_type ) 
    573573                $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_type = 'page'"); 
    574574 
     575        $wpdb->query("UPDATE $wpdb->posts SET post_parent = 0 WHERE post_parent = $postid AND post_type = 'attachment'"); 
     576 
    575577        $wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $postid"); 
    576578 
    577579        $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID = $postid");