@@ -69,16 +69,18 @@ protected static function generate_term_ids( $limit, $taxonomy, $name = '' ) {
6969 return $ term_ids ;
7070 }
7171
72- $ words = explode ( ' ' , ucwords ( $ name ) );
73- $ extra_terms = explode ( ' , ' , self ::$ faker ->department ( $ limit ) );
72+ $ words = str_word_count ( $ name, 1 );
73+ $ extra_terms = str_word_count ( implode ( ' ' , self ::$ faker ->department ( $ limit ) ), 1 );
7474 $ words = array_merge ( $ words , $ extra_terms );
7575
7676 if ( 'product_cat ' === $ taxonomy ) {
7777 $ terms = array_slice ( $ words , 1 );
7878 } else {
79- $ terms = array_merge ( self ::$ faker ->words ( $ limit ), array_map ( ' strtolower ' , $ words ) );
79+ $ terms = array_merge ( self ::$ faker ->words ( $ limit ), array ( strtolower ( $ words[ 0 ] ) ) );
8080 }
8181
82+ $ args = array ( 'parent ' => 0 );
83+
8284 foreach ( $ terms as $ term ) {
8385 if ( isset ( self ::$ term_ids [ $ taxonomy ], self ::$ term_ids [ $ taxonomy ][ $ term ] ) ) {
8486 $ term_ids [] = self ::$ term_ids [ $ taxonomy ][ $ term ];
@@ -91,7 +93,7 @@ protected static function generate_term_ids( $limit, $taxonomy, $name = '' ) {
9193 if ( $ existing && ! is_wp_error ( $ existing ) ) {
9294 $ term_id = $ existing ->term_id ;
9395 } else {
94- $ term_ob = wp_insert_term ( $ term , $ taxonomy );
96+ $ term_ob = wp_insert_term ( $ term , $ taxonomy, $ args );
9597
9698 if ( $ term_ob && ! is_wp_error ( $ term_ob ) ) {
9799 $ term_id = $ term_ob ['term_id ' ];
@@ -101,6 +103,7 @@ protected static function generate_term_ids( $limit, $taxonomy, $name = '' ) {
101103 if ( $ term_id ) {
102104 $ term_ids [] = $ term_id ;
103105 self ::$ term_ids [ $ taxonomy ][ $ term ] = $ term_id ;
106+ $ args ['parent ' ] = $ term_id ;
104107 }
105108 }
106109
0 commit comments