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 have a taxonomy location. All terms except one are to be treated differently. That's why I have two php files

  1. taxonomy-location.php
  2. taxonomy-location-national.php

Now, I want to make the URLs SEO friendly.

If URL = example.com/localdeals/national, I want to redirect it to taxonomy-location-national.php

If URL = example.com/localdeals/%any-other-term%, I want to redirect it to taxonomy-location.php

Basically I do not want to write the name of above files in .htaccess. I want to, somehow, reuse the default WordPress rules.

i.e. WordPress already directs example.com/?location=national and example.com/?location=boston correctly. I want to add new rules on top of these and want to reuse them.

Is it possible?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Note that the url-rewriting doesn't directly determine the template used. A pretty url is interpreted as a query and then that query determines what template is used based on the template hierarchy.

So only need one rule:

example.com/localdeals/myterm => example.com/?location=myterm

WordPress will look for the template taxonomy-location-myterm.php and use that (if it exists) or otherwise fallback to taxonomy-location.php

To add the above rule, when you register your taxonomy:

  register_taxonomy('location','post',array(
    'hierarchical' => false,
     ...
    'query_var' => true,
    'rewrite' => array( 'slug' => 'localdeals' ),
     ...
  ));

(you will need to flush these rules once after changing these - if this is for a plug-in/theme, only flush on activation/de-activation). Otherwise, just visit Settings > Permlinks page, and they'll be flushed :).

share|improve this answer
    
Lovely! It works...thanks a lot! –  afnrf May 10 '12 at 12:27
add comment

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.