Custom Taxonomies and parents

How can I create a group of custom taxonomies with parents that would include a description for the parent and child taxonomy?

Here’s what I have so far. The parent and child are created with the descriptions but the child taxonomy is not listed under the parent.

Read More
$categories = array(
   'Category 01'=>'<a href="http://category01.com" target="_blank">Category 01</a>',
    );

foreach($categories as $category => $cat_desc){
    wp_insert_term(
      $category, // the term 
     'style', // the taxonomy
      array(
        'description'=> $cat_desc,
        'slug' => $category ,
      )
    );
};

// List out all Categories with subcategories
$styles = array(
    'Category 01' => array(
        'Subcategory 1A'  => 'Subcategory 1A Description<br><a href="http://www.category01/subcategory.php#1a" target="_blank">Subcategory 1A Description</a>', 
        'Subcategory 1B'  => 'Subcategory 1B Description<br><a href="http://www.category01/subcategory.php#1a" target="_blank">Subcategory 1B Description</a>', 
        'Subcategory 1C'  => 'Subcategory 1C Description<br><a href="http://www.category01/subcategory.php#1a" target="_blank">Subcategory 1C Description</a>',
        'Subcategory 1D'  => 'Subcategory 1D Description<br><a href="http://www.category01/subcategory.php#1a" target="_blank">Subcategory 1D Description</a>',
        'Subcategory 1E'  => 'Subcategory 1E Description<br><a href="http://www.category01/subcategory.php#1a" target="_blank">Subcategory 1E Description</a>',            
    )             
);

// Import each array as taxonomy with parent
foreach($styles as $bjcp_category => $bjcp_styles ){
$parent_term = term_exists( $bjcp_category , 'style' ); // array is returned if taxonomy is given
$parent_term_id = $parent_term['term_id']; // get numeric term id
foreach($bjcp_styles as $bjcp_style => $bjcp_style_desc){
    wp_insert_term(
        $bjcp_style, // the term 
        'style', // the taxonomy
        array(
          'description'=> $bjcp_style_desc,
          'slug' => $bjcp_style,
          'parent'=> $parent_term_id
        )
    );
}

I have a feeling that I’m creating the arrays in a less than efficient method. What would be the best way to accomplish this as I have over 100 custom taxonomies to import into my CPT and would like to have it done in one plugin.

My question is, how would I structure an array to include the parent and child taxonomies with descriptions for each?

Related posts