From d2fa84c740e3db0e58b0d23c8a64e9b47d408cf3 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 8 Oct 2008 21:42:52 +0000 Subject: [PATCH] Try to preserve post IDs during import git-svn-id: https://develop.svn.wordpress.org/trunk@9100 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/import/wordpress.php | 1 + wp-includes/post.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index 25a47e5fc9..a4ed7b75c3 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -430,6 +430,7 @@ class WP_Import { $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); + $postdata['import_id'] = $post_ID; if ($post_type == 'attachment') { $remote_url = $this->get_tag( $post, 'wp:attachment_url' ); if ( !$remote_url ) diff --git a/wp-includes/post.php b/wp-includes/post.php index 91ee32565f..e4eb12bb10 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1304,7 +1304,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) { $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', - 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => ''); + 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0); $postarr = wp_parse_args($postarr, $defaults); $postarr = sanitize_post($postarr, 'db'); @@ -1449,6 +1449,13 @@ function wp_insert_post($postarr = array(), $wp_error = false) { } else { if ( isset($post_mime_type) ) $data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update + // If there is a suggested ID, use it if not already present + if ( !empty($import_id) ) { + $import_id = (int) $import_id; + if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) { + $data['ID'] = $import_id; + } + } if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { if ( $wp_error ) return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);