Retain default category when converting categories to tags. fixes #4845
git-svn-id: http://svn.automattic.com/wordpress/trunk@6079 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c3155a54b2
commit
33953bc337
|
@ -126,12 +126,22 @@ class WP_Categories_to_Tags {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Set the category itself to $type from above
|
||||
$wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
|
||||
|
||||
// Set all parents to 0 (root-level) if their parent was the converted tag
|
||||
$wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
|
||||
// If the category is the default, leave category in place and create tag.
|
||||
if ( get_option('default_category') == $category->term_id ) {
|
||||
$id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug));
|
||||
$id = $id['term_taxonomy_id'];
|
||||
$posts = get_objects_in_term($category->term_id, 'category');
|
||||
foreach ( $posts as $post ) {
|
||||
if ( !$wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") )
|
||||
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')");
|
||||
}
|
||||
} else {
|
||||
// Change the category to a tag.
|
||||
$wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
|
||||
|
||||
// Set all parents to 0 (root-level) if their parent was the converted tag
|
||||
$wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
|
||||
}
|
||||
// Clean the cache
|
||||
clean_category_cache($category->term_id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue