• I am getting duplicate terms in my term table (with the same taxonomy in some cases) which happens only under certain circumstances and was wondering if this is a bug (and if so how to fix it).

    To recreate this: go to post -> categories and create a new category in which the name does not already exist in the term table and leave the slug blank (I’ll use ‘apples’ as an example). So now you should have a new category (also a new term in the term table) called ‘apples’ with the slug of ‘apples’ (if the slug was not already taken). Now try to do the exact same thing again with ‘apples’. You should get the message, “A term with the name provided already exists with this parent”, makes sense. Now create a new category called ‘Apples’ making sure the ‘A’ is upper case with no slug – the term/category should be created as ‘Apples’ with a slug of ‘apples-2’, so far so good. Now try to create the category ‘apples’ again (same case as the first time around). You should get the same message as earlier, “A term with the name provided already exists with this parent.”

    So far we have the term ‘apples’ with a slug of ‘apples’ and a term ‘Apples’ with a slug of ‘apples-2’ and post -> categories will not allow us to create a new category/term ‘apples’ because it already exists in the term table.

    Now the bug. Try creating a new category ‘Apples’ (respecting case) and leave the slug blank. It creates a new category/term with the name ‘Apples’ and slug ‘apples-3’. At this point you can continue to create new categories/terms called ‘Apples’, which keeps filling up the term table with new terms called ‘Apples’ pointing at new taxonomies created in the term_taxonomy table which are all ‘category’.

    Is this a bug and if so is there a way to fix it? I have been poking around in the code and WP tables and noticed that in the term table the names are stored with a collation that is case insensitive (utf8_general_ci). I’ve also noticed that some term name comparisons done in the functions term_exists and wp_insert_term in the file wp-includes/taxonomy.php are done in PHP and in MySQL. The potential problem with this is that PHP comparisons will be case sensitive where as the MySQL comparisons won’t be with the collation used (unless a type cast is used like BINARY).

    Also, here is a link to the culprit that was causing issues which lead me here (terms join term_taxonomy on term_id): https://i.imgur.com/bFZkbFq.jpg and here is the change that “fixed” it (also removed the extra terms with term_id of 662 & 664): https://i.imgur.com/myLBZ7O.png

Viewing 3 replies - 1 through 3 (of 3 total)
  • Same here… Is this an actual bug or is there a way to get around this?

    Thread Starter Matt Brooks

    (@mbrooks34)

    This seems like a bug to me and the only way I’ve been able to “fix it” is to remove the duplicate entries from the tables and make sure that the case used for any term is consistent across the board. I never filed a bug report because I never had anyone verify that this is an issue.

    Same here.. I fixed it the same way btw.. seems like a weird bug to me…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Term Duplication Bug w/ Case’ is closed to new replies.