指定のtaxonomy以下のtermを取得する関数

指定のtaxonomy以下のtermを取得する関数

//指定taxonomy以下のtermを取得
※$slug=タクソノミースラッグ

function my_custom_get_tarm($slug) {
    $terms = get_terms($slug,'hide_empty=0', 'order=menu_order'); //hide_empty=0に設定することで、記事の登録の無いリンクも表示
    $tax = array();
    $ct   = 0;
    if(!empty( $terms ) && !is_wp_error( $terms )){
        foreach ( $terms as $term ) {
            $tax[$ct]['slug'] = $term->slug;
            $tax[$ct]['name'] = $term->name;
            $tax[$ct]['link'] = get_term_link($term);
            $ct++;
        }
    }
    return $tax;
}