WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm struggling to set up the structure of my wordpress site correctly so that the slugs, work correctly.

The page & custom post setup works fine and is as follows:

Archive for fruits (page):
- site.com/fruits
Singular fruits (custom post)
---- site.com/fruit/apple
---- site.com/fruit/pear

Archive for Veg (page):
- site.com/vegtables
Singular fruits (custom post)
---- site.com/vegtable/spud
---- site.com/vegtable/carrot

I would like to include a custom taxonomy, say colour, and using the plural have the following permalink:

Archive page for fruits by colour
- site.com/fruits/colour/green
- site.com/fruits/colour/red

I have been going round in circles trying to figure this out, but I believe the correct method would be:

 Create a page template for the custom post  custom taxonomy archive, e.g
 and create a page for the above.

 Set permalinks so all request for
 - site.com/fruits/colour/%colour%
 go to the above page

Could some please clarify that this would be the best method, if would they have any pointers as to how I may actually achieve this? If it isn't, could someone please suggest the preferred method.

Any assistance would be greatly appreciated.



share|improve this question
up vote 1 down vote accepted

All of the cases you describe are handled by the post type archive, post type single, and taxonomy term archive pages that are all automatically generated (depending on arguments) when you register your post type and taxonomy.

function wpd_add_custom_types() {

    // register fruit post type
    $args = array(
        'public' => true,
        'label'  => 'Fruit',
        'has_archive' => 'fruits', // all posts of type fruit
        'rewrite' => array( 'slug' => 'fruit' ) // single fruit
    register_post_type( 'fruit', $args );

    // register colour taxonomy
    $args = array(
        'label' => 'Colour',
        'rewrite' => array( 'slug' => 'fruits/colour' ) // all fruits of colour
    register_taxonomy( 'colour', 'fruit', $args );

add_action( 'init', 'wpd_add_custom_types' );
share|improve this answer
cheers for the reply. How do I get the taxonomy rewrite slug to work for more than one post type? Eg fruit and vegetables – noelmcg May 9 '14 at 23:33
that's a little more complicated, since a taxonomy only has a single URL. you'll have to add another rewrite rule which sets the post_type and colour query vars for vegetables and the requested colour. you'll also have to add a pre_get_posts filter to limit the fruits/colour URLs to just the fruit post type. – Milo May 9 '14 at 23:42
Is it definitely possible for me to have a page with the same slug that the has_archive points towards? This causes a conflict as wordpress is looking for the archive as opposed to the page? – noelmcg May 10 '14 at 21:11
if you want to use a page, set has_archive to false. – Milo May 10 '14 at 22:41

Your Answer


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.