Categories and Post Tags boxes are built-in meta boxes that have been already registered in WordPress. We can use them not only for default posts or pages but also for custom post types as well in WordPress. And this can be done easily with argument taxonomies of register_post_type() function when registering new custom post type.

In this example, I’ll register a new post type called “demo” with categories and post tags boxes:

add_action('init', 'demo_register_post_type');

function demo_register_post_type() {
    register_post_type('demo', array(
        'labels' => array(
            'name' => 'Demos',
            'singular_name' => 'Demo',
            'add_new' => 'Add new demo',
            'edit_item' => 'Edit demo',
            'new_item' => 'New demo',
            'view_item' => 'View demo',
            'search_items' => 'Search demos',
            'not_found' => 'No demos found',
            'not_found_in_trash' => 'No demos found in Trash'
        'public' => true,
        'supports' => array(
        'taxonomies' => array('category', 'post_tag') // this is IMPORTANT

The taxonomies is an array of registered taxonomies that will be used with this post type. The taxonomy for categories is category and for post tags is post_tag. Both of them are automatically registered, and we can use them without re-defining.

Sometimes, your blog has registered a custom post type already, and you don’t want to search in a bunch of code just to find out where the register_post_type() function to add a small line for categories and post tags boxes. To solve this problem, you can add them (categories and post tags boxes) later using register_taxonomy_for_object_type() function like this:

add_action('init', 'demo_add_default_boxes');

function demo_add_default_boxes() {
    register_taxonomy_for_object_type('category', 'demo');
    register_taxonomy_for_object_type('post_tag', 'demo');

Note that all these functions have to be called with init action hook. Otherwise, the custom post type is still registered, but no categories or post tags boxes.


  1. Thank you So much !!!!!

  2. Really nice article and very clearly explained. I’ve seen plenty of articles that make creating custom meta boxes seem really complex, but this lays it out very simply.

  3. Great, very helpful! Thanks!

  4. it’s possible remove slug? My structure is /%postname%/

  5. thanks for the tutorial. just fixed a site..!

  6. Oliver Nielsen

    April 29, 2014 at 8:15 PM

    Thanks for sharing. Just what I was looking for. Hadn’t expected it to be this easy (after having looked in WordPress Codex first)


  7. Iftekhar Bhuiyan

    April 16, 2014 at 11:31 AM

    Hello Tran,
    Thank you very much for your post. I am well aware of the fact that we can use default “post_tag” taxonomy with CPTs or simply we can create another custom taxonomy for the same purpose. My question is, what would be the best practice?

    I have custom CPTs like tutorials, portfolio, themes etc. Should I use the default post_tag taxonomy for adding tags on posts or to create a new one? Thank you in advance.

    • rilwis

      April 17, 2014 at 4:53 PM

      IMHO, using default ‘post_tag’ for other CPTs is not a good idea. Think about situation when you click on a tag? What do you expect? List of posts or mixed of posts and ‘portfolios’?

      I always recommend using different taxonomies for different CPTs.

      • Iftekhar Bhuiyan

        April 18, 2014 at 3:39 AM

        Thank you very much for your prompt reply. What you just said, does make sense for sure and I agree with you. Thank you once again.

  8. Hi, I have managed to add the custom post type to the admin, make a new post and that shows fine on the front end. Categories and tags show in both front and back end. However on the front end, if i click on a category, the post doesnt show up on the archive page. Any help????
    I would really like to move all my current posts across to a new post type but without this working it makes things very difficult for me.

  9. Thanks you!!!

  10. Usefull post! Tanks a lot!

  11. Thanks for the tip, I find it very useful. Your work will appear on several websites that I’m currently working on, and you don’t even know it :-) That’s the beauty of writting nice little tutorials – making the World Wide Web a better place.

  12. Hi,

    I have a custom post type called Recipes that was coded into a theme I bought. What I would like to do is add categories to the custom post type since it already has tags. Could you help? Any help is welcomed.

  13. Thanks, Great Post Buddy..

  14. Great post. Thanks for sharing!

  15. Extremely helpful, thanks so much for sharing.
    This really opens up the custom post types functionality and makes it much more useful for me.

  16. Thanks the tags are working…

    BUT if I click on the ” Choose from the most used tags ”
    I get ” No tags found! “

  17. Very helpful post. I also wanted to say that I recognize the Genesis theme. It’s funny that I saw this site because I’ve been debating on which framework to buy, or even go with a free one like thematic. I’ve been using WP for a couple of years but have recently started to learn a little about theme development. Would you recommend Genesis? This is the exact theme that I was wanting to start with too.

    Thanks again for the post!

    • rilwis

      August 2, 2012 at 6:46 PM

      I recommend Genesis for SEO benefits. It’s the strongest thing of Genesis, which I think it does SEO best! Other things like code structure, modules, easy to extend, etc. I think every frameworks have.

  18. Hi,
    first of all great snippet, but i have aquestion
    when you add the categories to the custom post type demo is there any way to add the categories but excluding some of them (instead of being all added)?

    add_action(‘init’, ‘demo_add_default_boxes’);

    function demo_add_default_boxes() {
    register_taxonomy_for_object_type(‘category’, ‘demo’);
    register_taxonomy_for_object_type(‘post_tag’, ‘demo’);

    thanks in advanced

    • rilwis

      July 18, 2012 at 10:48 PM

      AFAIK, we don’t have any way to do that unless you use a custom taxonomy for ‘demo’ post type.

  19. My theme was missing tags for custom post types. Many thanks to you, I fixed it following your instruction.

  20. Simon Stafferton

    May 10, 2012 at 9:33 PM

    Awesome – this is so simple and worked perfectly for me, trying to get another plugin (Geo-mashup) to work with custom post types. All other possible solutions looked massively involved, this fixed things with 3 lines of code. Many thanks!

  21. Thanks a lot, i was stuck on this for a day. By the way is thr a way to display a subset of categories (limited by a parent category key) in this category list for a custom post type. tx again!

  22. Dorian Speed

    May 2, 2012 at 6:50 PM

    Perfect! This is just what I needed to know. I found your site via the WordPress experts group on LinkedIn and I appreciate all of the helpful content you’re providing.

  23. Thanks guy, i am looking for this and you help me a lot!

  24. Matthew Boynes

    April 18, 2012 at 1:03 AM

    FGreat post, thanks for sharing. From the comments, for `rw_add_custom_post_types`, that should actually be:
    function rw_add_custom_post_types( $query ) {
    if ( $query->is_tag )
    $query->set('post_type', array('post', 'movies', 'actors'));
    return $query;

  25. Thank you, very helpful for me.

    i can make category & tag in my custom page.

    thank you.

  26. Great tips. Does it work in Thesis?

  27. Hi and thanks a lot for this great tutorial. I have the same problem as some other people here though. I’ve created a custom post type for quizzes on my website but I can’t seem to get it to show. I’m using the theme Sight, where all the categories are shown in the header. I want one of those categories to show all my quizzes.

    This is the code I’ve got in my functions.php right now:

    add_action(‘init’, ‘create_quizzes’);

    function create_quizzes() {
    register_post_type(‘quiz’, array(
    ‘labels’ => array(
    ‘name’ => ‘Quizzes’,
    ‘singular_name’ => ‘Quiz’,
    ‘add_new’ => ‘Lägg till quiz’,
    ‘edit_item’ => ‘Redigera quiz’,
    ‘new_item’ => ‘Nytt quiz’,
    ‘view_item’ => ‘View quiz’,
    ‘search_items’ => ‘Search quizzes’,
    ‘not_found’ => ‘No quizzes found’,
    ‘not_found_in_trash’ => ‘No quizzes found in Trash’
    ‘public’ => true,
    ‘supports’ => array(
    ‘taxonomies’ => array(‘category’, ‘post_tag’) // this is IMPORTANT

    add_action(‘init’, ‘quiz_add_default_boxes’);

    function quiz_add_default_boxes() {
    register_taxonomy_for_object_type(‘category’, ‘quiz’);
    register_taxonomy_for_object_type(‘post_tag’, ‘quiz’);

    add_action( ‘pre_get_posts’, ‘rw_add_custom_post_types’ );

    function rw_add_custom_post_types( $query ) {
    if ( is_search( ) || is_tax( ) )
    $query[‘quiz’] = array(‘quiz’, ‘movies’, ‘actors’);

  28. Thank you so much for this great information. was looking it and ws not able to find it. thanks to your blog.

    Salman Sohail

  29. Great stuff. Exactly what I was looking for but Im using Marketpress (which uses custom posts for products) and Ive implemented your code above so I can assign products to standard wordpress categories & tags. I can see the category & tag boxes but when I do a search or click on tag cloud in frontend I cannot see my products in the results. I also tried adding the pre_get_posts code to functions but no good. Help!

    • rilwis

      February 22, 2012 at 1:50 PM

      By default, WP uses only ‘post’ post type for search page and category and tag page. Using ‘pre_get_posts’ hook is right solution. I guess the problem is how you apply hook for ‘pre_get_posts’. If you can post your code here, then I can help you.

  30. I have read this post with great interest. However, I can not seem to show Custom Post Types that contain the same tags/categories as normal posts on the same page.

    I have added the code, as mentioned above eg pre_get_posts, changed the permalinks, saved changes but still cannot see my custom posts listed with standard posts with the same tags. I have also noted the following error when using search – ‘Cannot use object of type WP_Query as array in … functions.php line…’

    Can anyone shed any light on what my problem could be. I am trying this on WP 3.3.1 with Twenty Eleven Theme and no plugins.

  31. Thank you!! This works but my custom post is limited to title and excerpt. How do I add html/visual editor and featured image to the post type? Thank you so much.

    • rilwis

      February 16, 2012 at 1:37 PM

      You should add an attribute ‘support’ => array( ‘title’, ‘editor’, … ) when you register the custom post type.

  32. Tnx man….you save me a lot of time…all the best

  33. but exactly in which file we put the above code

  34. Im new in blogging, i dont know how to configure it….any plugin that can install easyly? Sorry…

  35. i spent hours and hours trying to figure this out! thanks so much!
    i just have one question, do they have the same functionality? ive set several tags, but if i do a search the related posts dont appear, neighter if i press one of the tags in the tag cloud..

    just wondering whats missing now.. if you have any clues i would be really thankfull, again ;)

    • rilwis

      December 1, 2011 at 3:32 AM

      Hi emiliano, the “tags” and “cateogries” of course have the same functionality. But by default WP don’t include custom post types in search result or archive page. That’s why you don’t see your posts with custom post type there. To make this done, you should hook into pre_get_posts action and add your custom post type, like this:

      add_action( 'pre_get_posts', 'rw_add_custom_post_types' );
      function rw_add_custom_post_types( $query ) {
          if ( $query->is_search || $query->is_tag ) 
             $query->set('post_type', array( 'post', 'movies', 'actors' ) );
      • Where do I add this? To the archive page or functions?

      • This Breaks the site when I add it to functions.php

      • Yeah this just breaks my site too. Any suggestions?

        • is “is_tax()” not “is_ta()”

        • rilwis

          January 31, 2012 at 3:59 AM

          Thanks Ed, just fixed.

        • this isn’t working for me. I added that code under the code in your post and all it does it break search.

          So while the custom post type stuff all works, it doesn’t display anywhere on my blog regardless of choosing a category or tag. Help!

        • Tran Ngoc Tuan Anh

          April 18, 2012 at 1:38 AM

          Just fixed the code.

        • Ah, nice, this answered my question above. Note that if you want them to show up on category archive pages as well, you need to add something extra Here it all is:

          add_action( ‘pre_get_posts’, ‘cpt_add_custom_post_types’ );

          function cpt_add_custom_post_types( $query ) {
          if ( $query->is_search || $query->is_tag || $query->is_category )
          $query->set(‘post_type’, array( ‘post’, ‘cpt_images’) );

      • Great Thanks!!!
        I’m happy that found this page))

  36. but where do I insert the mentioned code?

  37. Hi there,

    This page has certainly clarified somethings but I have been struggling all afternoon with my cpt’s. I used a ‘custom post type UI’ plugin but when I categorise my cpt’s I get a return of ‘nothing found so I cut and pasted your code without changing anything to see would this solve things.

    I get a ‘demos’ custom type with categories & tags (all good). I make a new demo and categorise it and publish. All fine, but when I click on the category under which the demo was included and I still get a return of ‘nothing found’. Any ideas what is going wrong. I’m just using WP twenty eleven default theme.



    • rilwis

      November 18, 2011 at 1:47 AM

      Maybe you should flush the rewrite rule by going to Settings -> Permalinks.

      • I had the same problem, flushed the rewrite rule in permalinks, but nothing.

        Any clue on what to do?

        • I’m also having this issue, where Custom Post Types do not show up on Category Archive pages…normal posts in a particular category are showing, but no custom post types do. Any ideas?

        • This is probably very very old, but did you manage to get custom post types to show in the category archives?? Im really struggling to get this to work

  38. this worked for me…anyways i need help with related post for custom post types using tags…any help will be appreciated.thank you!

  39. Great! It works :) Thanks a lot!

  40. Is there a way to separate the categories and tags for custom post types from those used for posts on the blog?

    • rilwis

      October 18, 2011 at 3:12 AM

      You should create custom taxonomies for custom post types, of course you can use the name “Category” or “Tag” to make them friendly.

  41. works perfectly. thank you.

  42. Thanks for the great tutorial, previously I used a plugin to do that and now hopefully I managed to integrate directly into the theme files.

  43. Very useful. Thanks!

  44. thanks! I was looking at much more complex solutions to put the default category menu on my custom post but this was so much easier. I like the 2nd suggestion if you don’t know the post or when it was registered, just tack it to the bottom to have it add it.

  45.  This is exactly what I needed…thank you SOOO much!!  :D

Leave a Reply

Your email address will not be published.