Display a specific hierarchical level of a specific custom taxonomy

Change:

  • get_the_category() to get_the_terms( null, 'taxonomy_name' ).
  • get_category_link( $cat->cat_ID ) to get_term_link( $cat->term_id ).
  • get_category( $category->category_parent ) to get_term( $category->parent ).

If you want to use the same function for multiple taxonomies, you can accept the taxonomy name as an argument and pass it to the first item above:

function display_cat_level( $level = 0 , $link = false, $taxonomy = 'category' ){
    $cats = get_the_terms( null, $taxonomy );
    // etc.
}

Also, even when working with categories, don’t use cat_ID and category_parent. Those were deprecated 11 years ago in favour of term_id and parent.