Term management tools - silently merge tags when converting

  • Download Gist
term-management-tools.merge-tags-when-converting.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
diff -u ./term-management-tools/term-management-tools.orig.php ./term-management-tools/term-management-tools.php
--- ./term-management-tools/term-management-tools.orig.php 2013-08-27 13:06:32.000000000 -0400
+++ ./term-management-tools/term-management-tools.php 2013-08-27 13:43:24.000000000 -0400
@@ -175,6 +175,17 @@
);
}
 
+ $term2 = get_term_by('name', $term->name, $new_tax);
+ if ($term2) {
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->term_relationships SET term_taxonomy_id=%d WHERE term_taxonomy_id=%d",
+ $term2->term_taxonomy_id, $term->term_taxonomy_id ));
+ wp_delete_term( $term_id, $term->taxonomy );
+ } else {
+ $wpdb->query( $wpdb->prepare( "
+ UPDATE $wpdb->term_taxonomy SET taxonomy = %s WHERE term_taxonomy_id = %d
+ ", $new_tax, $term->term_taxonomy_id ) );
+ }
+
$tt_ids[] = $term->term_taxonomy_id;
 
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
@@ -187,10 +198,6 @@
}
$tt_ids = implode( ',', array_map( 'absint', $tt_ids ) );
 
- $wpdb->query( $wpdb->prepare( "
- UPDATE $wpdb->term_taxonomy SET taxonomy = %s WHERE term_taxonomy_id IN ($tt_ids)
- ", $new_tax ) );
-
if ( is_taxonomy_hierarchical( $taxonomy ) && !is_taxonomy_hierarchical( $new_tax ) ) {
$wpdb->query( "UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE term_taxonomy_id IN ($tt_ids)" );
}
 
Diff finished. Tue Aug 27 13:44:27 2013

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.