4

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?

2 Answers 2

3

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),
    )
);
1

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.

1
  • This answer is quite useful, but I require a solution I can write as PHP code. Commented Oct 3, 2011 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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