Changeset 5229
- Timestamp:
- 04/10/2007 04:57:21 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wp-cat2tag.php
r5218 r5229 15 15 16 16 function populate_all_categories() { 17 $this->all_categories =& get_categories('hide_empty=0&hierarchal=0'); 17 global $wpdb; 18 19 $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 ORDER BY cat_name ASC"); 18 20 } 19 21 … … 71 73 } 72 74 75 function _category_exists($cat_id) { 76 global $wpdb; 77 78 $cat_id = (int) $cat_id; 79 80 $maybe_exists = $wpdb->get_results("SELECT cat_ID from $wpdb->categories WHERE cat_ID = '$cat_id'"); 81 82 if (count($maybe_exists) > 0) { 83 return true; 84 } else { 85 return false; 86 } 87 } 88 73 89 function convert_them() { 74 90 global $wpdb; … … 90 106 print '<li>' . __('Converting category') . ' #' . $cat_id . '... '; 91 107 92 if (! category_exists($cat_id)) {108 if (!$this->_category_exists($cat_id)) { 93 109 _e('Category doesn\'t exist!'); 94 110 } else { … … 101 117 } 102 118 119 // Set the category itself to $type from above 103 120 $wpdb->query("UPDATE $wpdb->categories SET type = '$type' WHERE cat_ID = '{$category->cat_ID}'"); 104 121 105 $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE cat_ID = '{$category->cat_ID}'"); 122 // Set relationships in post2cat to 'tag', category_count becomes tag_count 123 $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE category_ID = '{$category->cat_ID}'"); 106 124 $wpdb->query("UPDATE $wpdb->categories SET tag_count = '{$category->category_count}', category_count = '0' WHERE cat_ID = '{$category->cat_ID}'"); 125 126 // Set all parents to 0 (root-level) if their parent was the converted tag 127 $wpdb->query("UPDATE $wpdb->categories SET category_parent = 0 WHERE category_parent = '{$category->cat_ID}'"); 128 129 // Clean the cache 130 clean_category_cache($category->cat_ID); 107 131 108 132 _e('Converted successfully.'); … … 113 137 114 138 print '</ul>'; 115 116 clean_category_cache();117 139 } 118 140
Note: See TracChangeset
for help on using the changeset viewer.