{"id":4562532,"date":"2014-01-31T11:53:26","date_gmt":"2014-01-31T11:53:26","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/fix-for-duplicate-categories\/"},"modified":"2016-08-21T15:21:08","modified_gmt":"2016-08-21T15:21:08","slug":"fix-for-duplicate-categories","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/fix-for-duplicate-categories\/","title":{"rendered":"Fix for Duplicate Categories"},"content":{"rendered":"<p>After finding out that it was the WordPress importer plugin causing imported custom posts to create multiple categories with a dash plus number on the end (Example: category, category-1, category-2) when they should be in the same category I figured out this fix for the problem. To be specific the problem was occurring with a custom post type which had a custom taxonomy associated with it ( Custom Post Type of Jobs, and a Custom Taxonomy of Job Categories). <\/p>\n<p>All of the changes are to the main plugin file, wordpress-importer.php .<\/p>\n<p>First I commented out line 645 so it should now look like this:<\/p>\n<pre><code>\/\/$term_id = is_array( $term_exists ) ? $term_exists[&#039;term_id&#039;] : $term_exists;<\/code><\/pre>\n<p>Immediately after this I added this code to replace it starting on line 646:<\/p>\n<pre><code>if ( $term_exists !== 0 &amp;&amp; $term_exists !== null ) {\n     $term_id = $term_exists[&#039;term_id&#039;];\n}\nelse {\n     unset($term_id);\n}<\/code><\/pre>\n<p>Also, I commented out line 664 and changed the function from wp_set_post_terms to wp_set_object_terms:<\/p>\n<pre><code>\/\/$tt_ids = wp_set_post_terms( $post_id, $ids, $tax );\n$tt_ids = wp_set_object_terms( $post_id, $ids, $tax );<\/code><\/pre>\n<p>I have changed wp_set_post_terms to wp_set_object_terms since the former just references the latter and in my case I was dealing with a custom post type \/ custom taxonomy, but this would still work properly without this last change.<\/p>\n<p>https:\/\/wordpress.org\/plugins\/wordpress-importer\/<\/p>\n","protected":false},"template":"","class_list":["post-4562532","topic","type-topic","status-closed","hentry","topic-tag-custom-post-type","topic-tag-custom-taxonomy","topic-tag-duplicate-categories"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4562532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4562532\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4562532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}