Help with hierarchical custom taxonomies and permalinks…almost there

Ok, I managed to get it working by hooking into the ‘request’ filter, then checking to see if the last segment is term or not. If it’s not, change the $request var:

function alter_the_query( $request ) {
    $dummy_query = new WP_Query();  // the query isn't run if we don't pass any query vars
    $dummy_query->parse_query( $request );

    if ( !$dummy_query->is_admin && isset($request['tc_product_type']) ){       
        $lastSegment = basename($request['tc_product_type']);
        if(get_term_by('slug',$lastSegment,  'tc_product_type') === FALSE){
            $request['post_type'] = 'tc_products';
            $request['tc_products'] = $lastSegment;
            $request['name'] = $lastSegment;
        }
    }

    return $request;
}
add_filter( 'request', 'alter_the_query' );

Leave a Comment