Make WordPress Core

Ticket #9471: _relocate_children.diff

File _relocate_children.diff, 1.2 KB (added by scribu, 15 years ago)

use postmeta to save the temp_ID

  • wp-includes/post.php

     
    25552555
    25562556        clean_post_cache($post_ID);
    25572557
     2558        if ( isset($post_parent) && $post_parent < 0 )
     2559                add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true);
     2560
    25582561        if ( $update) {
    25592562                do_action('edit_attachment', $post_ID);
    25602563        } else {
  • wp-admin/includes/post.php

     
    759759        global $wpdb;
    760760        $old_ID = (int) $old_ID;
    761761        $new_ID = (int) $new_ID;
    762         return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) );
     762       
     763        $children = $wpdb->get_col("
     764                SELECT post_id
     765                FROM $wpdb->postmeta
     766                WHERE meta_key = '_wp_attachment_temp_parent'
     767                AND meta_value = $old_ID
     768        ");
     769
     770        foreach ( $children as $child_id ) {
     771                $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) );
     772                delete_post_meta($child_id, '_wp_attachment_temp_parent');
     773        }
    763774}
    764775
    765776/**