Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Tag panel in custom post type

I just made a custom post type. How do I display the Tag panel on the sidebar same as what the Post post type has?

like image 669
enchance Avatar asked Apr 20 '12 11:04

enchance


Video Answer


3 Answers

add this line to the section you register_post_type in functions.php in your theme folder

'taxonomies' => array('category', 'post_tag') 

The full code is looks like this

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'posttypename',
        array(
            'labels' => array(
                'name' => __( 'PostTypeName' ),
                'singular_name' => __( 'PostTypeName' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'posttypename'),
            'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' ),
            'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
        )
    );
}
like image 184
Sujith Kumar KS Avatar answered Sep 17 '22 23:09

Sujith Kumar KS


If you use 'taxonomies' => array('category', 'post_tag') then wordpress default post's tags will be display in the custom post type area.

Here is the clean and unique way for "news" post type.No mixing with other custom post types,default tags,..etc.

You can follow full details of "create custom post types and tags with categories" from this link.

add_action( 'init', 'news_tag_taxonomies' ); //change order add_action( 'init', 'news_tag_taxonomies', 0 );

//create two taxonomies, genres and tags for the post type "tag"
function news_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','news',array( // replace your post type with "news"
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tag' ),
  ));
}

Hope this would be help.

like image 20
Sumith Harshan Avatar answered Sep 18 '22 23:09

Sumith Harshan


All I needed to add apart from default WP codex template was

'taxonomies' => array('post_tag'),    
like image 28
kaczorro Avatar answered Sep 16 '22 23:09

kaczorro