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.

Standard WordPress post types have "Post Tags" which can be used to "tag" posts with similar content, makes those similar posts easily accessible just by opening that particular tag page and receiving the list of all posts.

I need exactly the same thing with my custom post types:

  • ability to tag the post with multiple tags
  • ability to list all custom posts tagged with the same tag by opening that tag page

How do I add support for adding tags to my custom post types?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I actually managed to figure it out and did it just beside the code of my custom post type. Like Fred suggested, I need to add a taxonomy to my custom post type called "tag".

And this is the way to do it:

register_taxonomy
(
    'myposttype-tag',
    array('myposttype'),
    array
    (
        'hierarchical' => false,
        'labels' => array
        (
            'name' => _x( 'My Post Type Tags', 'taxonomy general name' ),
            'singular_name' => _x( 'My Post Type Tag', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search My Post Type Tags' ),
            'all_items' => __( 'All My Post Type Tags' ),
            'edit_item' => __( 'Edit My Post Type Tag' ), 
            'update_item' => __( 'Update My Post Type Tag' ),
            'add_new_item' => __( 'Add New My Post Type Tag' ),
            'new_item_name' => __( 'New My Post Type Tag Name' ),
            'menu_name' => __( 'My Post Type Tags' ),
        ),
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'myposttype-tag', 'with_front' => true),
    )
);
share|improve this answer
add comment

Easy. Funny enough I was tackling that very same issue myself.

Get yourself the "Custom Post Type UI" plugin. Create a custom taxonomy for your custom post type, called "tag".

Whenever the user creates a new custom post, she will always be able to add a tag.

This tag should then be available in the form of a permalink and deliver all the custom post that are labeled under it.

share|improve this answer
    
This answer is quite useful, but I require a solution I can write as PHP code. –  Miljenko Barbir Oct 3 '11 at 18:51
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.