Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a Custom Post type and in that custom post type have a hierarchical taxonomy (categories).

Here's an example of the categories I made:

Hats
 - Mens
 - Womens

Shoes
 - Mens
 - Womens

The problem is that when I go to the "Mens" sub-category of the "Shoes" Main category it goes to the Mens category of the "Hats" category, i'm guessing it's because the URL of the two is the same.

What is the best way around this problem?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

This is a problem with wordpress that happened to me as well. If the titles of 2 terms (even if they are from different taxonomy), wordpress will not create another term in the database, instead link the previous term to taxonomy. If you look in your database, you'll find only 1 term with title "Mens" which will be a child of both Hats & Shoes. Also if you try to change the title/slug of one of those terms, wordpress will change the corresponding term under other taxonomy too. You can't separate them like this right now

Interestingly, if the terms you created were "Mens" & "mens", wordpress takes the slug of the 2nd to be "mens-2" & then it works as normal. I don't know if it's intentional but this thing was very frustrating the first time i found out.

share|improve this answer
    
Yeah it is frustrating, I discovered with custom taxomonmies you can use this function: get_term_link( $term->slug, $taxonomyName ); it actually works and solved my problem. With regular wordpress categories it might work as well I haven't tested it. –  Talon Oct 23 '12 at 18:38
    
The main problem arises when in future you want to change one of their titles & sadly there's no way to do it. You can unlink one of them & recreate it but then you'll have to reassign all the posts. –  Mridul Aggarwal Oct 23 '12 at 18:42
    
Would that problem be avoided if I was able to find away to use the Term ID rather than slug? I tried $term->term_id but that didn't work and I also tried $term->id –  Talon Oct 23 '12 at 23:09
    
won't work. title/slug/ID everything gets linked together. The only option is to unlink it using phpmyadmin or writing some custom wordpress code to overcome this kind of situation –  Mridul Aggarwal Oct 24 '12 at 10:09

I just hit this problem with regards to trying to automatically clear out terms for a custom taxonomy using TSQL, where terms from my main categories taxonomy with the same name would be deleted when I was only trying to delete terms associated with my custom taxonomy.

In regards to the issue of the two taxonomies having the same URL, have you tried applying a rewrite rule in your call to register_taxonomy()? For instance, I've got a main category "Baby", which lives at /baby, and a custom taxonomy for polls, which uses the very same term, "Baby", but lives at /polls/cat/baby.

It looks like this:

register_taxonomy(  
  'poll_category',  
  array('poll'),  
  array(  
    'public' => true,
    'hierarchical' => true,  
    'label' => 'Poll Category',  
    'query_var' => 'poll_category',  
    'rewrite' => array("slug" => "polls/cat", 'with_front' => FALSE), 
  )  
);  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.