50 responses to “A refresher on custom taxonomies”

  1. Ade

    I’ve been very interested in custom taxonomies, since your original articles about a year ago (referred to at the top of this article)

    I’ve had some fun making a little database website, similar to your own ‘movie database’ demo, maybe one day that will see the light of day as a serious website… but for now my main interest in custom taxonomies is how can i apply them to my main website

    I’d like to split up my original ‘tags cloud’ into specific topics rather than just a random collection of unrelated terms

    However this is where Wordpress core falls down…. There seems to be no way to change the relationship of old tags that already exist in my mysql database, from the original tag cloud into the new custom taxonomies

    I tried asking for help over on WP support forums, but no-one has any solution

    http://wordpress.org/support/topic/406956?replies=7

    It seems this is going to need to solved by a plugin before these custom taxonomies become of any use to WP users with older already established websites

    Still, this is great news for people starting brand new websites from scratch

  2. Glen Pridgen

    Thanks for the update….I have been hoping for this. I used your movie database tutorial on several client projects and will do the same with this one as well. Theme Hybrid+Custom Tax=Client Love!

  3. Eric Rasch

    This should go straight into the Codex! Just like Ade, I’ve been interested in taxonomies/custom post types/content types for quite some time now. This post update couldn’t have come at a better time as I was just working on a new website yesterday and creating custom post types for it.

    I installed a couple of plugins (Custom Post Type UI, CMS Press, etc.) to begin creating the new post types. Since this was the first chance I’ve had to use WP3.0 & post types, I went with the plugins vs. coding by hand (which with you post, I feel more confident about).

    I see the benefits of coding by hand, since you’ll have total control over the content types. What I seem to be missing is where I can use and benefit from using the content types within the WP3.0 admin area.

    For example, I started using the new WP menu system, and while it’s awesome to be able to select from Pages + Categories, it didn’t seem to recognize that I have taxonomies & content types of my own. Did they skip this type of connection or am I just not seeing how to link them? At that point, it seems like I would be better off just using Categories since the rest of the system recognizes them.

    1. Eric Rasch

      So, after testing the custom post type plugins I mentioned vs. hand-coding like Justin details, the hand-coded method *does* allow custom post types & taxonomies to appear in the new WP3.0 built-in menu system.

  4. Brian McDaniel

    Thanks for this, Justin. Couldn’t be more timely, as I just was Googling for info on this and came to your original article but needed more info. Perfect!

    I have a question for you: how would I call custom taxonomies from a nav menu? In other words, if I had Category A (or Custom Taxonomy A) and a sub-menu item of Custom Taxonomy X, how would I call them in a nav menu so that I could either go to posts in Cat A, or a listing of posts that are ONLY in BOTH Cat A and Tax X. Make sense?

    The nav menu would look like this:

    Category A (links to all posts in Cat A)
    - Custom Taxonomy X (links to all posts in Cat A with Tax X assigned)

    Thanks in advance for your guidance and much appreciate your hard work in putting these detailed explanations together!

  5. Andrew Nacin
  6. Wordpress 3.0 Custom Taxonomy

    [...] Tadlock has written a new article about  new wordpress 3.0 custom taxonomy features as and update to his old article about how to [...]

  7. The WordPress 3.0 edition: Friday Find

    [...] Tadlock gave us a great ‘Refresher on custom taxonomies’. This builds on a past article where custom taxonomies was looked at and now he goes back and looks [...]

  8. Thomas Clausen

    The problem I see now is that there’s one more question that needs answering — how to merge taxonomies and post types. I’ve touched on this a bit in this post, but you can expect a real-world example from me in the near future.

    This must be a fantastic event plugin from your hand :-) I think a event-plugin would be fantastic in combining the two.

    For instance for music-events we would have:
    Concert/Band: Custom post type
    Musician: Custom taxonomy
    Venue: Custom taxonomy
    Price range: Custom taxonomy
    Genre: Custom taxonomy
    Where to buy tickets: Custom taxonomy

    For a theater event we would have:
    Play: Custom post type
    Actors: Custom taxonomy
    Director: Custom taxonomy
    Theater/place: Custom taxonomy (but probably another one)

    This would also combine great with your members plugin. And then we would just need a great search plugin to utilize the power of this segmentation :-)

    All we would miss from this kind of event plugin would be time and Google maps integration. But that could be handled with custom fields for the first and another plugin for the later :-)

  9. Best On WordPress From The Past Week N.10 » wpCanyon

    [...] A Refresher On Custom Taxonomies [...]

  10. Andrew

    This is a very timely article indeed! A new era is indeed coming for taxonomies.

  11. Angelia

    Since you’re doing this refresher, I thought it might be a good place to ask if you have any insight on displaying a list of hierarchical taxonomy terms related to a specific post on the single post template? I’ve been going nuts with this.

    We can use the wp_list_categories function to list terms of a taxonomy in a nice hierarchical fashion with links … but, their is no way to pass it a post-id in order to only retrieve the terms of the current post.

    We can use the get_terms_list function in order to pass a post-id, but, then we have no way to maintain the hierarchy and have to manually code it.

    I’m sure as many others begin to take full advantage of these new capabilities, this will become a major hurdle, as it is for me at the moment, so, hoping someone can give some insight?

    It would be great to see a wp_list_terms function that would take a post-id filter, list hierarchically or not, link to term archive etc. in the future.

  12. Angelia

    Anyone who finds themselves in the same head banging dilemma I was in of how to actually show the hierarchical structure of your custom hierarchical taxonomy terms as they relate to a single post, Scribu has come to the rescue with a great explanation of how to accomplish this. Check it out here: http://scribu.net/wordpress/extending-the-category-walker.html#comment-3776

  13. Adam

    That was a great article on custom taxonomies. I have been using them for a while and I love the. If people aren’t using them they need to be because they work.

  14. The Wham

    I am amazed you got the refresher. Your information blows the codex away. In a way, it does show how much of a blog CMS Wordpress is and how much publishing and meta-development has yet to converge. Most people who needs these particular taxonomies will learn how to use php to their advantage and find better solutions with making their own plugins, or will defer to developers who will not use Wordpress.

    But, there is a good crowd of people who like the convenience of the system and the backend. Giving your tutorial has given hope to those who want to make Wordpress better. I hope an API page is made soon. I might take a run at after I get use to all the functions it has to offer.

  15. Troy

    Hey Justin,

    Thanks for all of the great posts. I’ve been reading through them all day. I have one thing that I can’t seem to get working an was hoping you might be able to help me with. When I create a taxonomy.php page I copied the content from categories.php and then added the following under

    Then in order to display my taxonomy list I use:

    printf( __( 'Posts classified under: %s', 'twentyten' ), '' . $term_name . '' );

    For the life of me I cant seem to get this to work. The output is always blank after “Posts classified under:”. I feel like i must be doing something wrong with get_term_by.

    This has been evading me all day, any help would be greatly appreciated.

    Troy

    1. Jonathan Wold

      Replace: $term_name

      With: $term->name

  16. Troy

    Hey Justin,

    Sorry I forgot to add part of my original comment, this one is hopefully complete.

    Thanks for all of the great posts. I’ve been reading through them all day. I have one thing that I can’t seem to get working an was hoping you might be able to help me with. When I create a taxonomy.php page I copied the content from categories.php and then added the following under get_header.

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

    Then in order to display my taxonomy list I use:

    printf( __( ‘Posts classified under: %s’, ‘twentyten’ ), ” . $term_name . ” );

    For the life of me I cant seem to get this to work. The output is always blank after “Posts classified under:”. I feel like i must be doing something wrong with get_term_by.

    This has been evading me all day, any help would be greatly appreciated.

    Troy

    1. Ryan

      I had the same issue as you and used the following to finally get it to work.

      name; ?>
  17. Kadir

    Great article. But I don’t know why I couldn’t do it. I make a mistake somwhere.

  18. christopher

    You sir, are a life saver.

    I’m not looking forward to reworking all of my code to take advantage of WP 3.0 taxonomies, especially hierarchies, but it’s going to be worth it when it’s all done.

  19. Mans

    I have problem with permalink rewrite,

    look at this page (http://weblifes.com/category/taxonom/),
    here I tried Taxonomy all work fine.

    The structure of permalink is ok, but all the post direct the latest post(single post) of “custom_post_type”.

    the url structure is different but all page is refer to most recent post.

    sorry for my english.

  20. Jinsona

    On a theme I am working on I have created a custom taxonomy called ‘genre’. I have terms like scifi, Comedy, Drama , action etc, under this ‘genre’ taxonomy.

    I am trying to make a custom taxonomy selection option in my theme option page so that I can query post with any specific term in that custom taxonomy. I have been trying to get this done using the get_terms function.

    The code I am using for it is this,

    $zm_terms_obj = get_terms(‘genre’) ;//genre is the name of my custom taxonomy
    $zm_terms = array();
    foreach ($zm_terms_obj as $zm_term) {
    $zm_terms[$zm_term->term_id]=$zm_term->name;
    }
    $terms_tmp = array_unshift( $zm_terms, “Select a genre:”);

    and for select option

    array( “name” => “Movie Genre”,
    “desc” => “”,
    “id” => $shortname.”_mgenre”,
    “std” => “Select a genre:”,
    “type” => “select”,
    “options” => $zm_terms),

    Now when I go to the theme option page and try to select a genre it is supposed to list options like scifi, comedy, drama, action. But I find the select field blank. No terms are listed. Has anyone else tried this? any suggestion?

  21. John Cole

    Thanks for the great articles.

    I’m trying to solve what I would think would be a pretty common issue for artists/bands who are using WP and need to display an extensive discography on their site.

    The new custom content types and taxonomies features in 3.0 seem like they will go along ways towards doing this. I’ve made some progress setting up a possible solution, but I keep having the feeling I’m re-inventing the wheel here and that someone else must have already done this.

    I’ve seen the old ‘Discography’ plugin, but it isn’t quite there in my opinion. Is there anyone else out there working on something similar?

  22. Using a custom taxonomy to display related posts

    [...] actually quite simple: a custom taxonomy called relations. How to create a custom taxonomy can be found here, I’ll concentrate on my little [...]

  23. angga

    how to display all post with custom taxonomy,
    i’ve ‘music’ taxonomy, music has 2 sub/cat, ‘rock’ and ‘jazz’..etc
    for now i can display with ‘rock’ and ‘jazz’, etc (all sub/cat of this music taxonomy)

    but i dont know how to display all post with this ‘music’ taxonomy.

    anyone know about this?

    1. Giovanni

      Why would you want to do that? Do you query posts who all have ‘tags’?

    2. Giovanni

      I think it’s best to make a post-type music.

    3. Christopher

      I’m trying to figure out the same thing but with bars and restaurants. In my case, I have a food and drink category that lists all bars and restaurants and I’m using taxonomies break those down into specifics.

      Similar to what you are facing, I have a ‘cuisine’ taxonomy for different food styles (American/Chinese etc…) and it’s not a problem to get a list of all Chinese or American restaurants but I’m stuck figuring out how to get a list of everything that falls under ‘cuisine’ taxonomy.

      I can solve this using additional categories but it’s not an ideal solution.

  24. Jacob

    Thanks for this!

    Is it possible to redirect taxonomies? I have dynamic php pages that I use for each game on my football site and would like to create taxonomies that will link directly to that game’s page instead of an archive page. Is there something built into wordpress that can pull this off?

  25. Kevin

    wow, great info here on taxonomies, im going to try them out on our company recently upgraded wordpress 3.0 blog and will let you know of our finding. thanks.

  26. ferar

    For me as a novice blogger, your article was very interesting, optimization tool, the well itself shows.

  27. greven

    Thanks for the article Justin. I’ve been using taxonomies since my last project, a Portuguese website dedicated to Online Gaming and MMOs. I use Taxonomies to classify posts as Guides, Articles, News, Videos. I use Categories for the Games, World of Warcraft, Starcraft, etc. I use Tags as tags are used, for specific subjects.

    Taxonomies are great, they allow me to organize my website better.

    But there is something I’m having trouble with since 2.9 and I don’t think it’s fixed on 3.0. It’s the is_tax() function. I wanted to use it so if the current page is a taxonomie, similar to is_category() so I would put that specific Title on that page.

    The problem is that I think that function is returning false when it should return true.

    For example, if you go to this page: http://massivo.net/type/artigo/ That is a taxonomy Artigo of Post Type (slug: type). I used this on the archive page:


    Artigos

    But it doesn’t return true so I don’t have a title for that page. Anyway know a way around this?

  28. greven

    I don’t think the code rendered well… Sorry for that.

    (...) elseif( is_tax('artigo') ) {Artigos

  29. Kevinjohn Gallagher

    Is there any way of setting “default” selected custom taxonomies?
    Is there any way of doing this programatically based on data passed through?

    In the most abstract of examples:

    I have a custom taxonomy (SLEEPY) with options called DAY and NIGHT.

    Is there a way of setting a function call on the loading of the meta box so that I can dynamically set these as default as needed?

    Thanks

  30. Rick Adlam

    Great article on the ‘hard to get my head around’ topic of taxonomies in general and WordPress Taxonomies.
    I am still not clear on content and taxonomy classification.
    With a mortgage site example where you have:
    Funders of Mortgages:
    E.g. Banks, securitised lenders and private funders as sources of mortgage finance,
    Mortgage Distribution models.
    Banks [with up to 8 different channels for distribution of mortgage products, e.g, bank branches, online direct, mobile direct, franchised partners, financial planners, and mortgage brokers ]

    Securitised lenders: [Some of which are bank owned]
    Direct, Wholesale, introducers, mortgage managers, mortgage brokers or variations or omissions on these channels. e.g. Some only direct, some only through mortgage brokers, some only through mortgage managers.
    Mortgage loan types split several ways e.g.:
    Revolving credit lines,
    Interest only
    Variable Principal and interest
    Mixtures of these
    Loan Pricing models
    Basic discount
    Introductory discounts [ e.g. special rate for 3, 6 or 12 months, or fixed rate for 3 years then reverts to variable rate]
    professional packages and bundled packages
    Loan size discounts e.g [over $300,000 get a better rate for life]

    Which are the taxonomy and which are the content in these areas ?

  31. Justin B

    I can’t wait to upgrade my blog site to 3.0… there are just way too many things I can’t do with 2.0, and a lot of things just take way too long!

  32. Adrienne Adams

    I was having a bear of a problem with empty taxonomies breaking the page.
    I looked around a bit and realized I had to add a check to see if the taxonomy exists:

    ID,  'register', 'Registered: ',  ' ' , ''); ?>

    Unfortunately the documentation on custom taxonomies mostly fail to address this problem.

    1. Adrienne Adams

      Oh crap. Why can’t we post code here? Here’s the link to my snippet:
      http://cloudislands.com/samples/snip-2.txt

  33. Jauhari

    With Taxonomies we can create unlimited possibilities with WordPress

  34. Egyptological

    Your earlier posts worked perfectly for creating custom taxonomies in WP2.9 and I agree witht he comment that this article should go into the codex.
    Kate

  35. William Chen

    I’m hooked on Wordpress :3 <33

  36. Brad

    Thanks for the articles!

    I’ve been using your articles and a few others to help me piece together some fairly good functionality for a website I’m working on. BUT I’ve run into a problem.

    I’m using the taxonomies as hierarchical and I’ve made this work with the wordpress menu. I’ll have several layers of menu options, but when I click on a parent which has no items in it I get nothing found, but would like to show the children’s posts. If this makes any sense… :P

    Example: website.com/catalog/nascar <– shows nothing found
    website.com/catalog/nascar/dale <— shows all the dale items.

    Example: I would like website.com/catalog/nascar to show all children items.

    Children Examples: website.com/catalog/nascar/team-caliber/
    website.com/catalog/nascar/dale

    Thank you any help would be appreciated.

    -Brad

  37. Wok

    When you add custom taxonmies for custom posttypes, and then display taxonomy information using filters and actions on the ‘manage_posts_custom_column’ ‘manage_edit-portfolio_columns’ hooks on the admin/edit.php pages they are not searchable.

    Only select dropboxes only let you sort/filter by month.

    Any ideas how to get this going? Kind of sad to have the power of taxonomies, but with out the ability to sort through them, when you have 100 attached posts, and your listings for each taxonomy grows it become a big management problem. Just putting it out there for disscussion…

  38. Rick

    Justin,

    First of all, thanks for your articles, they’re very enlightening.

    Is it possible to assign custom taxonomies to user profiles like you do with posts, pages or custom post types? The goal is to show filtered members’ lists according to the tags/categories they choose to be listed in.

    So far I couldn’t find a way to do this :(

  39. Jimmy@Taiwan

    Hi all,
    I’ve a question, I’ve create a custom type and add a custom taxonomy, in the admin i would like to filter the custom post by taxonomy (with a select box), it works like that for regular post, I didn’t find hot to do it for a custom post type.

  40. WordPress 3.0 – The Ultimate Roundup For Developers & Users | KreativeThemes.com

    [...] be managed with ‘Categories’ and ‘Tags’ only).Custom Post Types in WordPressA Refresher on Custom TaxonomiesWordPress 3.0 and Custom Post TypesFirst Impressions of Custom Post TypeCreating Custom Taxonomies [...]

  41. Rob Felty

    Thanks for a great post Justin. I would like to know where the labels and other options of the register_taxonomy function get stored in the database. Does anyone know?

  42. Chief Alchemist

    This is one half hey, “check this out” and one half a cry for help :)

    The short of it is, in terms of build in functions, taxonomies don’t seem to be very well supported, yet. So it looked like a custom function was in order. I needed to take all the taxonomy terms for a post, mash them together, sort them (alpha on the taxonomy->name) and spit them out again.

    Yes, I know that it kinda defeats the purpose of taxonomies but there is ultimately a method to this madness so please just play along :)

    Finally, I don’t process to be a PHP coder. I get by. So please feel free to add your two or three cents. Ultimately, I’d like to add the taxonomy-> description as well. But one step at a time, eh?

    Thanks in advance. Here goes nuttin’…

    function funct_PostAllTaxSorted($parm_PostID, $separator)
    {
    global $wp_taxonomies;
    $str_PostTaxList = '';
    	// get all the taxonomies
         foreach ($wp_taxonomies as $taxonomy)
            {
    			// except those listed on this array
    	      	if ( in_array($taxonomy->name, array('category', 'link_category') ) == false )
              	{
                 	$str_PostTaxList .=get_the_term_list($parm_PostID,  $taxonomy->name,'','|','|');
    	      	}
    	   }
    	   if (isset($str_PostTaxList))
    	   {
    		   // trim off any blanks as well as the extra | at the end of the string. for somme odd reason rtrim didn't want to strip off the extra |
    			trim('$str_PostTaxList');
    			$str_PostTaxList = substr($str_PostTaxList,0,(strlen($str_PostTaxList)-1));
    			// convert the string into an array
    	       	$arr_PostTaxList = explode('|',$str_PostTaxList);
    		   	$str_StripTags = '';
    		   	$arr_ListByTaxKey = array();
    			// build a new array using (what is ultimately) the taxonomy->name as the array key
    		   	foreach ($arr_PostTaxList as $str_PostTaxSingle)
    		   	{
    				$str_StripTags = strip_tags($str_PostTaxSingle);
    				$arr_ListByTaxKey[$str_StripTags] = $str_PostTaxSingle;
    			}
    			// sort the new array on the key
               ksort($arr_ListByTaxKey);
    		   $str_PostTaxListSorted = '';
    		   // take the sorted array and convert it back into a string of HTMK
    		   foreach ($arr_ListByTaxKey as $str_TaxKeySingle)
    		   {
    			   $str_PostTaxListSorted = $str_PostTaxListSorted.$str_TaxKeySingle.$separator;
    		   }
    		   // remove the extra separator that was appended to the end
    		   $str_PostTaxListSorted = substr($str_PostTaxListSorted,0,(strlen($str_PostTaxListSorted)-strlen($separator)));
    
    	   }
    return $str_PostTaxListSorted;
    }

    btw, for some reason I couldn’t get rtrim to work so that’s why I ended up using substr. Weird, right?

  43. Editing a book | Andrew Nacin

    [...] posts to get up to speed, not to mention relying on a few of his excellent plugins. Justin is my favorite WordPress tutorial writer out there. And I had the opportunity to meet Brad in WordCamp San [...]

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.