Try to preserve post IDs during import
git-svn-id: https://develop.svn.wordpress.org/trunk@9100 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b82dc680c5
commit
d2fa84c740
@ -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
|
$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 = 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') {
|
if ($post_type == 'attachment') {
|
||||||
$remote_url = $this->get_tag( $post, 'wp:attachment_url' );
|
$remote_url = $this->get_tag( $post, 'wp:attachment_url' );
|
||||||
if ( !$remote_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,
|
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
|
||||||
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
|
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
|
||||||
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
|
'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 = wp_parse_args($postarr, $defaults);
|
||||||
$postarr = sanitize_post($postarr, 'db');
|
$postarr = sanitize_post($postarr, 'db');
|
||||||
@ -1449,6 +1449,13 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
|
|||||||
} else {
|
} else {
|
||||||
if ( isset($post_mime_type) )
|
if ( isset($post_mime_type) )
|
||||||
$data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update
|
$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 ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
|
||||||
if ( $wp_error )
|
if ( $wp_error )
|
||||||
return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
|
return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
|
||||||
|
Loading…
Reference in New Issue
Block a user