When building a WordPress site, it’s common to start with the default “post” post type and later introduce custom post types (CPTs) such as tech, artwork, beats, releases, or others. Often, posts are switched from “post” to a custom post type with a plugin like Post Type Switcher. However, a hidden issue can arise: legacy category assignments, especially the default “Uncategorized” remain attached to posts, even when categories are not supported or displayed for the custom post type.
Table of Contents
Why Does This Happen?
WordPress stores category relationships at the database level. Switching a post to a custom post type does not automatically remove its category assignments. If the post type does not register support for the category taxonomy, the category box disappears in the admin UI, but the underlying relationships persist.
This creates problems if you use content restriction plugins (such as Simple Membership) that operate based on category assignments. Even invisible category links, like “Uncategorized,” can restrict access to these posts unintentionally.
Symptoms
- Posts moved from “post” to a custom post type (e.g., tech) remain restricted by plugins targeting the “Uncategorized” category.
- You cannot unassign “Uncategorized” via the admin interface because the custom post type does not support categories.
Solution
To cleanly remove the “Uncategorized” category from each custom post type, you can use the following PHP snippet (run once, then delete). Replace ‘post_type’ => ‘your_custom_type’ for each CPT:
add_action('init', function() {
$uncat_id = get_cat_ID('Uncategorized'); // Use '未分類' if in Japanese
if (!$uncat_id) return;
$args = array(
'post_type' => 'your_custom_type', // e.g. 'tech', 'artwork', 'beats', 'releases'
'posts_per_page' => -1,
'post_status' => 'any',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $uncat_id,
),
),
);
$posts = get_posts($args);
foreach ($posts as $post) {
wp_remove_object_terms($post->ID, $uncat_id, 'category');
}
});
Example: To apply it for artwork, update ‘post_type’ => ‘artwork’. For a Japanese site, use get_cat_ID(‘未分類’) instead.
Important Notes
- Always backup your database before running code that modifies post relationships.
- Remove or deactivate the code after a successful run to prevent repeated operations.
- This code only affects the specified custom post type; posts still in the standard “post” type are unaffected.
Alternative Approaches
If you cannot run PHP code, or if your site cache interferes:
- Ask your developer or host to run a direct SQL query (with backups).
- Update restriction plugin logic to ignore categories for custom post types (not a true cleanup, but functional).
Conclusion
Switching post types in WordPress is powerful, but can leave unexpected database connections. By cleaning up category assignments for your CPTs, you can ensure proper plugin operation and maintain content access as intended. This solution provides a safe, targeted way to remove “Uncategorized” from your custom post types now, and in the future.