• 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).

    All of the changes are to the main plugin file, wordpress-importer.php .

    First I commented out line 645 so it should now look like this:

    //$term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;

    Immediately after this I added this code to replace it starting on line 646:

    if ( $term_exists !== 0 && $term_exists !== null ) {
         $term_id = $term_exists['term_id'];
    else {

    Also, I commented out line 664 and changed the function from wp_set_post_terms to wp_set_object_terms:

    //$tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
    $tt_ids = wp_set_object_terms( $post_id, $ids, $tax );

    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.


Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fix for Duplicate Categories’ is closed to new replies.