[wp-hackers] wanting to select no categories

Mike Little wordpress at zed1.com
Fri Jul 20 16:05:04 UTC 2012


On 20 July 2012 16:15, Kevinjohn Gallagher
<kevinjohngallagher at hotmail.com>wrote:

> Folks,
> How do I set a post to have NO categories?(yeah, i know, sounds simple)
> Every time I uncheck categories, it adds the default in as standard.
> Kev
>
>
If you want no categories for any posts you can remove the taxonomy from
posts:

add_action( 'init', 'unregister_categories_from_posts');
function unregister_categories_from_posts(){
global $wp_taxonomies;
$taxonomy = 'category';
 $post_type = 'post';
 if ( taxonomy_exists( $taxonomy)) {
 $tax_entry = $wp_taxonomies[$taxonomy];
foreach( $tax_entry->object_type as $index => $object_type )
 if ( $post_type ==  $object_type ) {
unset( $tax_entry->object_type[$index] );
 break;
}
}
 // or just remove the taxonomy, but other post type may use it.
//unset( $wp_taxonomies[$taxonomy]);
}


But if you only want *some* posts to have no category, you cannot as Otto
explained. Your best bet would be create a category to represent 'no
category' and make it the default category (so no action is required of the
user). Then hide that category from appearing in the theme, and if you
wanted to you could also hide it from the back end UI too.


Mike
-- 
Mike Little
http://zed1.com/


More information about the wp-hackers mailing list