Title: Improve Terms import
Last modified: February 10, 2022

---

# Improve Terms import

 *  [StephanR](https://wordpress.org/support/users/stephanr-1/)
 * (@stephanr-1)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/improve-terms-import/)
 * Hi,
 * When importing, child terms with the same names are not imported:
    —————-
 * > PARENT 1
   >  MyChild PARENT 2 MyChild here only the first mychild is imported
 * —————-
 * I fixed this in the class WP_Import process_terms() function by testing the parent
   before checking if the term exists.
 * Here is the original code:
    [https://plugins.trac.wordpress.org/browser/wordpress-importer/trunk/class-wp-import.php#L475](https://plugins.trac.wordpress.org/browser/wordpress-importer/trunk/class-wp-import.php#L475)
 * Here is the fix:
 *     ```
       if ( empty( $term['term_parent'] ) ) {
       	$parent = 0;
       } else {
       	$parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
       	if ( is_array( $parent ) ) {
       		$parent = $parent['term_id'];
       	}
       }
   
       // if the term already exists in the correct taxonomy leave it alone
       $term_id = term_exists( $term['slug'], $term['term_taxonomy'], $parent ); 
   
       if ( $term_id ) {
       	if ( is_array($term_id) ) $term_id = $term_id['term_id'];
       	if ( isset($term['term_id']) )
       		$this->processed_terms[intval($term['term_id'])] = (int) $term_id;
       	continue;
       }
       ```
   
 * Thanks,
 * Regards.
 * Stephan Renault

The topic ‘Improve Terms import’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-importer/assets/icon.svg?rev=2791650)
 * [WordPress Importer](https://wordpress.org/plugins/wordpress-importer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-importer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-importer/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-importer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-importer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-importer/reviews/)

## Tags

 * [child](https://wordpress.org/support/topic-tag/child/)
 * [Import](https://wordpress.org/support/topic-tag/import/)
 * [terms](https://wordpress.org/support/topic-tag/terms/)

 * 0 replies
 * 1 participant
 * Last reply from: [StephanR](https://wordpress.org/support/users/stephanr-1/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/improve-terms-import/)
 * Status: not a support question