From 24cb55366b5b67a5156e9cf504abb7b6d6ded812 Mon Sep 17 00:00:00 2001 From: David Cavins Date: Thu, 22 Jun 2017 09:54:47 -0500 Subject: [PATCH] Match existing terms when possible. When importing posts to a site as part of a multi-part import process, it's possible that categories and posts will not be imported in the same run. When importing posts separately from term information, match the post's term data to terms that already exist on the site when possible. --- class-wxr-importer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/class-wxr-importer.php b/class-wxr-importer.php index 51c6a80..55d313e 100644 --- a/class-wxr-importer.php +++ b/class-wxr-importer.php @@ -917,8 +917,13 @@ protected function process_post( $data, $meta, $comments, $terms ) { $taxonomy = $term['taxonomy']; $key = sha1( $taxonomy . ':' . $term['slug'] ); + // Add terms that were processed earlier in WXR import. if ( isset( $this->mapping['term'][ $key ] ) ) { $term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ]; + // Add terms that already exist on the site. + } else if ( $existing_term_id = $this->term_exists( $term ) ) { + $term_ids[ $taxonomy ][] = $existing_term_id; + // Add the term info as post meta for manual relinking. } else { $meta[] = array( 'key' => '_wxr_import_term', 'value' => $term ); $requires_remapping = true;