WordPress.org

Support

Support » Themes and Templates » Allow duplicate taxonomy slugs?

Allow duplicate taxonomy slugs?

  • I’m trying to set up a hierarchical taxonomy within my theme which also uses a hierarchical slug rewrite.

    This way I can have a category like “collections”, with a subcategory like “earrings” which yet another subcategory like “hoops”.

    One issue I’ve ran into is that there cannot be the same taxonomy slug stored, if a duplicate exists it appends the parent’s slug to the end. Is there any way to allow duplicate entries?

    The problem I have is that there are multiple sub-categories of the same name which exist in different categories, but are totally independant.

    Example:

    Collections/Necklaces/Simple-n-Chic
    Collections/Earrings/Simple-n-Chic

    However, in creating these links, after defining the first series the second one became:

    Collections/Earrings/Simple-n-Chic-Earrings

    I do not want this to occur, is there an alternative?

    EDIT: The code in use, although it’s currently not “working” on the front end.

    register_taxonomy(
        'collections', // name/slug
        'collections', // object type (custom)
        array(
          'name' => 'Collections',
          'hierarchical' => true,
          'update_count_callback' => '_update_post_term_count',
          'labels' => $labels,
          'show_ui' => true,
          'query_var' => true,
          'rewrite' => array( 'hierarchical' => true ),
        )
      );

    And here is a screenshot of the taxonomy itself, notice simple-n-chic-earrings… that’s the issue:

    http://radleygh.com/images/chrome_2012-222-20-10-15-8.png

Viewing 3 replies - 1 through 3 (of 3 total)
  • Did you ever find a solution to this? I have the same issue and I am looking for a work around.

    No I didn’t. I ended up using my own system using custom URL structure and completely abandoned the slug field for the category. I used “sanitize_title” on the title of the category to get a slug-formatted title. It’s all kind of hacky.

    If you want to set up a custom URL structure you can look up the filter “query_vars”, the function “add_rewrite_rule” and finally you can access your wildcard using “get_query_var”. Brian Fegter pointed me in the right direction for this on stackexchange: http://wordpress.stackexchange.com/questions/62846/using-custom-dynamic-slug-for-a-page

    Still, there may be a better way. Maybe one day when I have some more wordpress experience it will be worth making a plugin for this sort of category. But I don’t know.

    Good luck.

    There is a plugin “Duplicate Category Paths” which does this for 3.x so you can have the same seo friendly url paths.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Allow duplicate taxonomy slugs?’ is closed to new replies.
Skip to toolbar