How would I leverage custom Taxonomies in this scenario?

First I would create a new custom post type called Trips. Add this to your theme’s functions.php

//trips Custom Post Type
add_action( 'init', 'create_trips_post_type' );
function create_trips_post_type() {
register_post_type( 'trips',
    array(
        'labels' => array(
            'name' => __( 'Trips' ),
            'singular_name' => __( 'Trips' )
        ),
    'public' => true,
    'has_archive' => true, 
    'hierarchical' => true,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'excerpt'),
    'rewrite' => array('slug' => 'trips'),
    )
);

}

Then I would create a new custom taxonomy called ‘tripdetails’. Add this to your theme’s functions.php

//tripdetails custom taxonomy
function tripdetails_init() {
// create a new taxonomy
register_taxonomy(
    'tripdetails',
    array('trips'),
    array(
        'label' => __( 'Trip Details' ),
        'sort' => true,
        'args' => array( 'orderby' => 'term_order' ),
        'hierarchical' => true,
        'rewrite' => array( 'hierarchical' => true, 'slug' => 'tripdetails' ), 
    )
);
}
add_action( 'init', 'tripdetails_init' );

You’ll be able to then fill your custom taxonomy with terms and sub-terms of your own choosing.

Then when you create a new ‘Trip’ using your brand new custom post type you can simply tag it with terms and sub-terms from your brand new custom taxonomy.

You’ll end up with URLs like this (which will contain a list of your ‘trips’ which have been tagged with the appropriate terms)

http://example.com/tripdetails/top-level-term/second-level-term/

Leave a Comment