Reuse standard categories / taxonomy tags for custom post types?

In my wordpress theme functions.php, I created a custom post type called foobar. Can I reuse default categories and tags for foobar posts? Or do I need to create two taxonomies - one for categories and one for tags - to achieve this?

EDIT: I think I solved this using this code inside a function that creates a custom post type:

register_taxonomy_for_object_type('category', 'foobar'); register_taxonomy_for_object_type('post_tag', 'foobar'); 

I am CORRECT.

+8
wordpress wordpress-theming
source share
1 answer

You can kill two birds with one stone and use the taxonomies key when registering a message type :

 $product_labels = array( 'name' => _x('Products', 'post type general name'), 'singular_name' => _x('Product', 'post type singular name'), 'add_new' => _x('Add New', 'portfolio item'), 'add_new_item' => __('Add New Product'), 'edit_item' => __('Edit Product'), 'new_item' => __('New Product'), 'view_item' => __('View Product'), 'search_items' => __('Search Products'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $product_args = array( 'labels' => $product_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'product'), 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 2, 'supports' => array('title','editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'page-attributes', 'custom-fields', ), // Set the available taxonomies here 'taxonomies' => array('category', 'post_tag') ); register_post_type('product', $product_args); 
+5
source share

All Articles