How to include parent terms in hierarchical taxonomy URLs?

Just clarifying, what was pointed out by Parst with a working example of a custom taxonomy registration code:

$labels = array(
        'name'              => _x( 'Issue numbers', 'taxonomy general name', 'sascha_setup_post_type' ),
        'singular_name'     => _x( 'Issue number', 'taxonomy singular name', 'sascha_setup_post_type' ),
        'search_items'      => __( 'Search issues', 'sascha_setup_post_type' ),
        'all_items'         => __( 'All issue numbers', 'sascha_setup_post_type' ),
        'parent_item'       => __( 'Year of publication', 'sascha_setup_post_type' ),
        'parent_item_colon' => __( 'Year of publication:', 'sascha_setup_post_type' ),
        'edit_item'         => __( 'Edit issue number', 'sascha_setup_post_type' ),
        'update_item'       => __( 'Update issue number', 'sascha_setup_post_type' ),
        'add_new_item'      => __( 'Add new issue number', 'sascha_setup_post_type' ),
        'new_item_name'     => __( 'New issue number', 'sascha_setup_post_type' ),
        'menu_name'         => __( 'Issue numbers', 'sascha_setup_post_type' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'issues', 'hierarchical' => true ),
    );

    register_taxonomy( 'issue_number', array( 'post', 'issue' ), $args );

The result gives a url like www.yourdomain.com/issues/2016/04/ – just as you wanted it to be.
And! Don’t forget to flush your permalink rules after implementing this, not to get 404 for your custom taxonomy urls. The easiest way – go to Admin / Permalinks and just hit the “save” button, without changing anything.

Leave a Comment