Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called portfolio and I'm trying to add the tags taxonomy to it, how do I do this?

share|improve this question
    
@chifliiiii if I do that, the Categories and Tags are the same as the ones used for Posts. How do I get Categories and Tags that are exclusive to the new post type? –  Troy Templeman May 8 at 16:36
    
Please don't use the answer section to post comments/questions. please start your own question –  Pieter Goosen May 8 at 16:38

2 Answers 2

up vote 1 down vote accepted

Like this: (Where it says "portfolio" is where you register the taxonomy to a post type

add_action( 'init', 'create_tag_taxonomies', 0 );

//create two taxonomies, genres and tags for the post type "tag"
function create_tag_taxonomies() 
{
  // Add new taxonomy, NOT hierarchical (like tags)
  $labels = array(
    'name' => _x( 'Tags', 'taxonomy general name' ),
    'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Tags' ),
    'popular_items' => __( 'Popular Tags' ),
    'all_items' => __( 'All Tags' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Tag' ), 
    'update_item' => __( 'Update Tag' ),
    'add_new_item' => __( 'Add New Tag' ),
    'new_item_name' => __( 'New Tag Name' ),
    'separate_items_with_commas' => __( 'Separate tags with commas' ),
    'add_or_remove_items' => __( 'Add or remove tags' ),
    'choose_from_most_used' => __( 'Choose from the most used tags' ),
    'menu_name' => __( 'Tags' ),
  ); 

  register_taxonomy('tag','portfolio',array(
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tag' ),
  ));
}
?>
share|improve this answer
    
thanks! this worked perfectly –  Joe Bobby Aug 18 '12 at 23:54
    
@JoeBobby it would probably be worth checking out the WordPress Codex page for registering taxonomies to get a better feeling for all of the available options: codex.wordpress.org/Function_Reference/register_taxonomy –  Stephen S. May 8 at 16:41

or just add

'taxonomies' => array('post_tag')

to the $args array in the functions.php-file where you create the custom post type.

share|improve this answer
    
Please add an explanation to your answer: why could that solve the problem? –  toscho Jul 12 '13 at 3:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.