WordPress.org

Make WordPress Core

Ticket #13496: use-subquery-for-detached.13496.diff

File use-subquery-for-detached.13496.diff, 944 bytes (added by filosofo, 5 years ago)
  • wp-admin/upload.php

     
    2020        if ( !current_user_can('edit_posts') ) 
    2121                wp_die( __('You are not allowed to scan for lost attachments.') ); 
    2222 
    23         $all_posts = implode( ',', $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type NOT IN ('attachment', '" . join("', '", get_post_types( array( 'public' => false ) ) ) . "')" ) ); 
    24         $lost = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent > '0' and post_parent NOT IN ($all_posts)"); 
     23        $lost = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent > '0' and post_parent NOT IN ( SELECT ID FROM $wpdb->posts WHERE post_type NOT IN ('attachment', '" . join("', '", get_post_types( array( 'public' => false ) ) ) . "') )"); 
    2524         
    2625        $_GET['detached'] = 1; 
    2726