Index: wp-includes/category.php
===================================================================
--- wp-includes/category.php	(revision 5269)
+++ wp-includes/category.php	(working copy)
@@ -2,6 +2,7 @@
 
 define('TAXONOMY_CATEGORY', 1);
 define('TAXONOMY_TAG', 2);
+define('TAXONOMY_LINK_CATEGORY', 4);
 
 function get_all_category_ids() {
 	global $wpdb;
@@ -75,15 +76,17 @@
 	$exclusions = apply_filters('list_cats_exclusions', $exclusions, $r );
 	$where .= $exclusions;
 
+	if ( 'link' == $type )
+		$where .= ' AND ( type & ' . TAXONOMY_LINK_CATEGORY . ' != 0 ) ';
+	else
+		$where .= ' AND ( type & ' . TAXONOMY_CATEGORY . ' != 0 ) ';
+
 	if ( $hide_empty && !$hierarchical ) {
 		if ( 'link' == $type )
 			$where .= ' AND link_count > 0';
 		else
 			$where .= ' AND category_count > 0';
-	} else {
-		$where .= ' AND ( type & ' . TAXONOMY_CATEGORY . ' != 0 ) ';
 	}
-
 	
 
 	if ( !empty($number) )
Index: wp-admin/upgrade-functions.php
===================================================================
--- wp-admin/upgrade-functions.php	(revision 5269)
+++ wp-admin/upgrade-functions.php	(working copy)
@@ -182,6 +182,9 @@
 	if ( $wp_current_db_version < 4772 )
 		upgrade_210();
 
+	if ( $wp_current_db_version < 5267 )
+		upgrade_220();
+
 	if ( $wp_current_db_version < 4351 )
 		upgrade_old_slugs();
 
@@ -565,6 +568,16 @@
 	}
 }
 
+function upgrade_220() {
+	global $wpdb, $wp_current_db_version;
+
+	// Set category type
+	if ( $wp_current_db_version < 5267 ) {
+		$wpdb->query("UPDATE $wpdb->categories SET type = type | " . TAXONOMY_CATEGORY . " WHERE category_count > 0");
+		$wpdb->query("UPDATE $wpdb->categories SET type = type | " . TAXONOMY_LINK_CATEGORY . " WHERE link_count > 0");
+	}
+}
+
 function upgrade_old_slugs() {
 	// upgrade people who were using the Redirect Old Slugs plugin
 	global $wpdb;
Index: wp-admin/upgrade-schema.php
===================================================================
--- wp-admin/upgrade-schema.php	(revision 5269)
+++ wp-admin/upgrade-schema.php	(working copy)
@@ -21,7 +21,7 @@
   tag_count bigint(20) NOT NULL default '0',
   posts_private tinyint(1) NOT NULL default '0',
   links_private tinyint(1) NOT NULL default '0',
-  type tinyint NOT NULL default '1',
+  type tinyint NOT NULL default '0',
   PRIMARY KEY  (cat_ID),
   KEY category_nicename (category_nicename)
 ) $charset_collate;

