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´m trying to create the following URL structure:

example.com/attractions                     <-- post type archive
example.com/attractions/taxonomy_term       <-- taxonomy archive
example.com/attractions/van-gogh-museum     <-- custom post type

Unfortunately this isn´t possible by default: WordPress needs the taxonomy base in the URL, as SE user sanchothefat wrote in his answer to this question:

...if you don't want the taxonomy-slug to be there then you're out of luck, you can't have the same slug as your post type or another taxonomy as it won't know what term is from which taxonomy and what's a post.

In other words, WordPress needs this permalink structure:

example.com/attractions/taxonomy_base/taxonomy_term

My question: Is there a way to make this work using WordPress rewrite API?

I suppose it involves 2 steps:

  1. Removing the taxonomy base from the URL
  2. Tell WordPress what post type it needs to display

Update #1

I found a code snippet that should remove the taxonomy base from the URL:

global $wp_rewrite;
$wp_rewrite->extra_permastructs['taxonomy_base'] = array('%taxonomy_base%', EP_NONE);

(Source - see last answer on bottom of page)

This isn´t the complete solution though, since WordPress can´t tell if the post is a taxonomy archive or a post type...


Update #2

The author of this great article on Advanced Taxonomy Queries with Pretty URLs wrote me:

What you're asking isn't too difficult, but it could be a bit tricky. The rewrite rules need to know what type of thing the second term is(..) That's why the category/tag/taxonomy name prefix is prepended. You could create a rewrite so that everything after /attractions/ is treated as a taxonomy URL, but doing both gets a little tricky.


Update #3

For anyone having the same issue, have a look at this discussion on WordPress Answers. Especially MikeSchinkel´s plugin code might help.

Here´s an interesting example of WPCandy combining the taxonomy base and term in the URL: http://wpcandy.com/pros/experienced/with-multisite

share|improve this question
    
Did you ever get this to work? –  Richard B Mar 14 '12 at 13:28
    
Unfortunately not, I moved on to other things after update #3. I still need to find a solution for this issue though. –  Mattvic Mar 14 '12 at 17:44

2 Answers 2

I just added a plugin to the Wordpress Directory that removes the slug base for any custom taxonomy and the default category taxonomy. You can find it here - http://wordpress.org/extend/plugins/wp-no-taxonomy-base/

share|improve this answer

Recently I came across the same situation, and after a day spent searching for a solution and couldn't find any, I wrote my own working solution.

The trick is to use Wordpress wp_rewrite, and to add your URLs to it when Wordpress generates its permalinks on the beginning.

I've wrote a simple function to do it all automatically and explained everything on my blog (don't want to paste the same code twice), so feel free to check it out ;)

http://someweblog.com/wordpress-custom-taxonomy-with-same-slug-as-custom-post-type/

share|improve this answer
1  
Welcome to WordPress Stack Exchange! An answer should be more than just a link to an external site. Please add a solution. –  toscho Dec 3 '12 at 15:46

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.