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 portfolio-post-type.php which contains this:

<?php
add_action( 'init', 'create_portfolio_post_type' );
function create_portfolio_post_type() {
    register_post_type( 'portfolio',
        array(
            'labels' => array(
                'name' => _x( 'Portfolio', 'post type general name', 'flowthemes' ),
                'singular_name' => __( 'Portfolio Item', 'post type singular name', 'flowthemes' ),
                'add_new' => _x('Add New', 'portfolio', 'flowthemes' ),
                'add_new_item' => __('Add New Portfolio Item', 'flowthemes' ),
                'edit_item' => __('Edit Portfolio Item', 'flowthemes' ),
                'new_item' => __('New Portfolio Item', 'flowthemes' ),
                'view_item' => __('View Portfolio Item', 'flowthemes' ),
                'search_items' => __('Search Portfolio Items', 'flowthemes' ),
                'not_found' =>  __('No portfolio items found', 'flowthemes' ),
                'not_found_in_trash' => __('No portfolio items found in Trash', 'flowthemes' ), 
                'parent_item_colon' => '',
                'menu_name' => _x( 'Portfolio', 'flowthemes' ),

            ),
            'public' => true,
            'exclude_from_search' => true,
            'has_archive' => false,
            'supports' => array('title', 'author', 'custom-fields', 'revisions', 'page-attributes', 'post-formats', 'comments', 'trackbacks', 'excerpt' ),
            'rewrite' => array('slug' => 'portfolio')
        )

    );
    register_taxonomy('portfolio_category','portfolio',array(
    'hierarchical' => true,
    'labels' => array(
        'name' => _x( 'Portfolio Categories', 'taxonomy general name', 'flowthemes' ),
        'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name', 'flowthemes' ),
        'search_items' =>  __( 'Search Categories', 'flowthemes' ),
        'popular_items' => __( 'Popular Categories', 'flowthemes' ),
        'all_items' => __( 'All Categories', 'flowthemes' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Portfolio Category', 'flowthemes' ), 
        'update_item' => __( 'Update Portfolio Category', 'flowthemes' ),
        'add_new_item' => __( 'Add New Portfolio Category', 'flowthemes' ),
        'new_item_name' => __( 'New Portfolio Category Name', 'flowthemes' ),
        'separate_items_with_commas' => __( 'Separate Portfolio category with commas', 'flowthemes' ),
        'add_or_remove_items' => __( 'Add or remove portfolio category', 'flowthemes' ),
        'choose_from_most_used' => __( 'Choose from the most used portfolio category', 'flowthemes' )
    ),
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => false,
    ));
}
?>

What I want to make is to add also support for tags, to be able to add also tags on portfolio post in the back-end. How can I accomplish this ?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Just add this code under your category registration. Check the register_taxonomy() function for more details.

Usually when you set hierarchical => true taxonomy looks like category and hierarchical => false its looks like tag.

register_taxonomy('portfolio_tag','portfolio',array(
'hierarchical' => false,
'labels' => array(
    'name' => _x( 'Portfolio Tags', 'taxonomy general name', 'flowthemes' ),
    'singular_name' => _x( 'Portfolio Tag', 'taxonomy singular name', 'flowthemes' ),
    'search_items' =>  __( 'Search Tags', 'flowthemes' ),
    'popular_items' => __( 'Popular Tags', 'flowthemes' ),
    'all_items' => __( 'All Tags', 'flowthemes' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Portfolio Tag', 'flowthemes' ), 
    'update_item' => __( 'Update Portfolio Tag', 'flowthemes' ),
    'add_new_item' => __( 'Add New Portfolio Tag', 'flowthemes' ),
    'new_item_name' => __( 'New Portfolio Tag Name', 'flowthemes' ),
    'separate_items_with_commas' => __( 'Separate Portfolio Tag with commas', 'flowthemes' ),
    'add_or_remove_items' => __( 'Add or remove portfolio Tag', 'flowthemes' ),
    'choose_from_most_used' => __( 'Choose from the most used portfolio Tag', 'flowthemes' )
),
'show_ui' => true,
'query_var' => true,
'rewrite' => false,
));

Showing tags on front end:

Tags: <?php echo get_the_term_list( $post->ID, 'portfolio_tag', '', ', ', '' ); ?>

Reference: http://codex.wordpress.org/Function_Reference/get_the_term_list

share|improve this answer
    
Thank you! Now what tag should I use to display the tags on the front-end? –  Alecs Jul 24 '12 at 22:26
    
Answer updated :) –  Sisir Jul 25 '12 at 8:02
    
I've tried to display portfolio tags from back-end but nothing displays. –  Alecs Jul 30 '12 at 0:15
    
not sure what you meant. On backend you should find the tag box on "Add new" page. If its isn't there click on screen option top of the page and check if the display option for the tag is turned off. –  Sisir Jul 30 '12 at 9:29
    
You missunderstood me, I want to display the tags also on the front-end, I mean on my website... –  Alecs Jul 30 '12 at 12:06
show 1 more comment

You need to add tags as a taxonomy when you register the post type. You can do this directly with register_taxonomy_for_object_type]1 or with the taxonomy array parameter of register_post_type.

share|improve this answer
add comment

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.