@@ -674,32 +674,31 @@ public function recount( $args ) {
674674 public function migrate ( $ args , $ assoc_args ) {
675675 // Code based from https://wordpress.org/plugins/taxonomy-converter/
676676 global $ wpdb ;
677- $ clean_term_cache = array ();
677+ $ clean_term_cache = $ values = array ();
678678 $ term_reference = $ args [0 ];
679679 $ original_taxonomy = Utils \get_flag_value ( $ assoc_args , 'from ' );
680680 $ destination_taxonomy = Utils \get_flag_value ( $ assoc_args , 'to ' );
681681
682682 $ term = get_term_by ( Utils \get_flag_value ( $ assoc_args , 'by ' ), $ term_reference , $ original_taxonomy );
683683
684- if ( ! empty ( $ term ) ) {
684+ if ( ! $ term ) {
685685 WP_CLI ::error ( "Taxonomy term ` {$ term_reference }` for taxonomy ` {$ original_taxonomy }` doesn't exist. " );
686686 }
687687
688688 $ original_taxonomy = get_taxonomy ( $ original_taxonomy );
689689
690- $ id = wp_insert_term ($ term ->name , $ destination_taxonomy , array ( 'slug ' => $ term ->slug ) );
690+ $ id = wp_insert_term ( $ term ->name , $ destination_taxonomy , array ( 'slug ' => $ term ->slug ) );
691691
692692 if ( is_wp_error ( $ id ) ) {
693693 WP_CLI ::error ( "An error has occured: " . $ id ->get_error_message () );
694694 }
695695
696- $ id = $ id ['term_taxonomy_id ' ];
697- $ posts = get_objects_in_term ( $ term ->term_id , $ original_taxonomy );
696+ $ posts = get_objects_in_term ( $ term ->term_id , $ original_taxonomy ->name );
698697
699698 foreach ( $ posts as $ post ) {
700699 $ type = get_post_type ( $ post );
701700 if ( in_array ( $ type , $ original_taxonomy ->object_type ) ) {
702- $ values [] = $ wpdb ->prepare ( "(%d, %d, %d) " , $ post , $ id , 0 );
701+ $ values [] = $ wpdb ->prepare ( "(%d, %d, %d) " , $ post , $ id[ ' term_taxonomy_id ' ] , 0 );
703702 }
704703
705704 clean_post_cache ( $ post );
@@ -714,18 +713,18 @@ public function migrate( $args, $assoc_args ) {
714713 $ clean_term_cache [] = $ term ->term_id ;
715714 }
716715
717- $ del = wp_delete_term ( $ term_id , $ tax );
716+ $ del = wp_delete_term ( $ term -> term_id , $ original_taxonomy );
718717
719718 if ( is_wp_error ( $ del ) ) {
720719 WP_CLI ::error ( "An error has occured: " . $ del ->get_error_message () );
721720 }
722721
723722 // Set all parents to 0 (root-level) if their parent was the converted tag
724- $ wpdb ->update ( $ wpdb ->term_taxonomy , array ( 'parent ' => 0 ), array ( 'parent ' => $ term_id , 'taxonomy ' => $ tax ) );
723+ $ wpdb ->update ( $ wpdb ->term_taxonomy , array ( 'parent ' => 0 ), array ( 'parent ' => $ term -> term_id , 'taxonomy ' => $ destination_taxonomy ) );
725724
726725 if ( ! empty ( $ clean_term_cache ) ) {
727726 $ clean_term_cache = array_unique ( array_values ( $ clean_term_cache ) );
728- clean_term_cache ( $ clean_term_cache , $ args [ 2 ] );
727+ clean_term_cache ( $ clean_term_cache , $ destination_taxonomy );
729728 }
730729 }
731730
0 commit comments