WordPress.org

Ready to get started?Download WordPress

Forums

Problem: Term used in more than one taxonomy causes duplicate slugs (11 posts)

  1. Oyblix
    Member
    Posted 2 years ago #

    Hello!

    This summer I was setting up a wordpress installation for a very complex site, with several custom posting types and relation taxonomies between almost all of them.

    This works well, apart from the problem I've encountered with using several (atleast more than one) taxonomies with the same term name. On some occations (as far as I can tell), terms get the slug form <slug name>-2 or even <slug name>-3 if the same term is used in different taxonomies. This causes some problems, because I've created the system to relate term slugs to names of custom posting types.

    Is this by design, and/or can I avoid it? How should i approach the taxonomy/terms to avoid this being a problem?

    (A little while out in the project, I realized that WordPress might not be the ideal choice for this kind of website, as 'post types' might not be what I'd call the stuff I use them for.)

  2. This is by design. Slugs have to be unique in order to avoid collisions.

  3. Oyblix
    Member
    Posted 2 years ago #

    Well yea, I get that. It's just that the structure of terms and taxonomies gives me the impression that if you try to create a term in one taxonomy, and that term already exists in another taxonomy, WordPress would just create a new relation for the same term, not create a duplicate. The term title is identical.

  4. All the terms, for all taxonomies (custom, tags, cats) are in one great big table: wp_terms

    It's not the best way to handle it, I agree, but it's what we've got and it's hard to split it up this late in the game.

    Now, you CAN reuse taxonomies between custom post types, IIRC (I'm a bit of a novice in them), but I believe it's in the registration of the taxonomy:

    See:
    http://stackoverflow.com/questions/3864572/in-wordpress-how-do-you-register-built-in-taxonomies-with-custom-post-types-in-co
    or
    http://wordpress.org/support/topic/register_taxonomy-to-re-use-taxononmies-over-multiple-custom-post-types?replies=6

  5. Oyblix
    Member
    Posted 2 years ago #

    I'm not reusing taxonomies, I'm simply having the same term in different ones. This gives a conflict because WordPress can't properly recognize that the new term already exists in the database, and therefore makes a duplicate. As the term is identical, so is the proposed slug, and therefore, it creates a "-2" version of it.

  6. Oyblix
    Member
    Posted 2 years ago #

    To illustrate, here's a screenshot of the result when querying for a term:

    SELECT * FROM wp_terms WHERE name = 'Mat og Drikke'

    http://i.imgur.com/HlHuk.jpg

  7. Oyblix
    Member
    Posted 2 years ago #

    Even better, this illustrates how it all seems quite inconsequent:

    SELECT term_id, name, slug, taxonomy FROM wp_terms NATURAL JOIN wp_term_taxonomy WHERE name = 'Mat og Drikke'

    http://i.imgur.com/WYSRa.jpg

  8. I'm not reusing taxonomies, I'm simply having the same term in different ones.

    Right, you can't do that if they have the same term name because of slug conflict :) That's as expected, and you, you can't fix it unless... as I'm suggesting, TRY reusing them, that is, use the same taxonomy in multiple CPTs. That might get around the issue by only having one taxonomy.

    (FYI in your second screenshot, look at the taxonomy number on the left - 28 is repeated, which means it's all the same tax, so it's all 'okay').

  9. Oyblix
    Member
    Posted 2 years ago #

    As I said, my last screenshot shows how inconsistent it is. For the first four entries, the term id is - as you noted - the same (i.e. the same term is used for different taxonomies). But for the last three, this is not the case. (I understand why the top 4 and the bottom 3 are separated, as they arent absolutely identical.)

  10. That may or may not be inconsistant.

    What;s the term_taxonomy_id in that table for those items?

  11. Oyblix
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic