0

To learn about Wordpress, I am building my own theme. I have created a Custom Post Type (CPT) called Golf Courses [golf-courses].

The CPT has hierarchical taxonomies which I have named (whilst learning) and laid out as follows:

Europe
 - UK
  - England

I then have a custom function that rewrites the URL so it would appear like this:

http://www.site.com/Europe/UK/England/stoke-park/

For what I am doing, my custom posts will not be in a child taxonomy without being in its parent (so for the example URL above it would never be in UK and not Europe as well).

What I am now trying to do without much luck is list all the posts in say UK under a URL like:

http://www.site.com/Europe/UK/

This doesn't work, but it seems such a simple concept that I don't see why not.

http://www.site.com/Europe/ or http://www.site.com/UK/ do work though.

What do I need to do to get this working, or is it impossible?

neildeadman
  • 3,974
  • 13
  • 42
  • 55

1 Answers1

0

When registering a new taxonomy add the rewrite parameter. In your case:

function build_taxonomies() {
    register_taxonomy( 'europe', 'homepage', array( 'hierarchical' => true, 'label' => 'Europe', 'query_var' => true, 'rewrite' => array( 'hierarchical' => true ) ) ); 
}
add_action( 'init', 'build_taxonomies', 0 );

Then add UK and then Stoke and nest stoke under UK (parent).

(also try flush your rewrite rules after you've added the code)

Moishy
  • 3,560
  • 3
  • 23
  • 42
  • Mark, I'm a little confused by how to do the nesting of stoke under UK that you mention. Any chance you can expand the answer to include an example? – neildeadman May 10 '14 at 16:50
  • @neildeadman add a new category called UK and by parent category select Europe – Moishy May 12 '14 at 22:20
  • Oh right, I thought it was some sort of nesting of register_taxonomy commands.. categories and not custom taxonomies :/ – neildeadman May 18 '14 at 08:09