Changeset 7645 for trunk/wp-admin/import/wp-cat2tag.php
- Timestamp:
- 04/14/2008 04:13:25 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/import/wp-cat2tag.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wp-cat2tag.php
r6950 r7645 165 165 $posts = get_objects_in_term($category->term_id, 'category'); 166 166 foreach ( $posts as $post ) { 167 if ( !$wpdb->get_var( "SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") )168 $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')");167 if ( !$wpdb->get_var( $wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $post, $id) ) ) 168 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (%d, %d)", $post, $id) ); 169 169 clean_post_cache($post); 170 170 } 171 171 } else { 172 $tt_ids = $wpdb->get_col( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");172 $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 173 173 if ( $tt_ids ) { 174 174 $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); … … 178 178 179 179 // Change the category to a tag. 180 $wpdb->query( "UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");181 182 $terms = $wpdb->get_col( "SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");180 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 181 182 $terms = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 183 183 foreach ( (array) $terms as $term ) 184 184 clean_category_cache($term); 185 185 186 186 // Set all parents to 0 (root-level) if their parent was the converted tag 187 $wpdb->query( "UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");187 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 188 188 } 189 189 // Clean the cache
Note: See TracChangeset
for help on using the changeset viewer.