Try to preserve post IDs during import
git-svn-id: http://svn.automattic.com/wordpress/trunk@9100 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aac340be40
commit
65660bd565
|
@ -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 )
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue