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.

What’s the best way to make Wordpress accept non-unique sub-category slugs?

By default, Wordpress ensures that every ‘slug’ portion of permalink URLs is unique, and is very savvy about using this to ensure you never see a 404 from omitting a portion of the URL. This means if my permalink structure is…

http://site-root.com/category-name/sub-category-name/post-name/post-id

Then….

will all take me to the same post.

But if that kind of fail-safe redirection is less important to someone than being able to have non-unique slugs (and nicely structured directories), I’m SOL.

Let’s say I’m writing a restaurant review guide in major cities. I want my top-level categories to be city names, and the types of restaurants to be the sub-categories. So I create “Boston”, “New York”, and “Seattle”, then I add the sub-categories “Chinese Food”, “Italian Eateries”, and “Luxury Dining” to Boston. But when I try to add the same sub-categories to New York, even when I specify the URL slugs, Wordpress starts forcing slugs like “http://[site-root].com/New-York/Chinese-Food-New-York/” — unnecessary repetition, and lengthening my links. This gets even worse if I want to have sub-sub-categories.

I haven’t yet been able to find a way to force Wordpress to accept non-unique slugs. How would you recommend I accomplish this?

share|improve this question
    
It seems Henk Jan is trying to solve exactly the same problem. He does it with two taxonomies: one for the region and one for the restaurant type, just like Voyagerfan5671 suggests. –  Jan Fabry Dec 28 '10 at 11:57

3 Answers 3

I'm struggling with complex category restrictions too. In your case, you might want to check out Pods CMS. It's a pretty sweet plugin that seems to have possibly stalled (release of 2.0 is a year overdue), but it gives you way more flexibility with relational posts ("pods") and url structure. The part that would be useful to you would be using wildcards for urls, so you can tell a certain "pod" to show up if the url matches something like boston/restaurants/* and another for boston/* and another for /* etc.

I guess you probably don't need a solution any more, but might be helpful to others. Or does anyone else know of plugins that give you that url wildcard functionality using WP's native custom post-types?

share|improve this answer

The short version is no, you can't do that. But similar to what Voyagerfan said, you may want to look into using a custom post type and and custom taxonomy. That way they aren't parent / child relationships, rather, separate types that can be sorted / queried on their own.

share|improve this answer

I'd look into using custom post types for the repetitive parts of your permalinks. Cities can be categories, and the restaurant types can be post types. It's the perfect use for post types, and it helps solve the problem.

Unfortunately I can only see it helping with one sub-level. If you need sub-sub-categories you'll have to find another WordPress feature with a URL presence that you can "bend" to fit your purpose.

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.