Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sachac/6356685 to your computer and use it in GitHub Desktop.
Save sachac/6356685 to your computer and use it in GitHub Desktop.
Term management tools - silently merge tags when converting
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment