Imagine you ran a website that reviewed books, movies, and music. When writing posts in WordPress, you want to label something as a book, yet you also want to further label it by genre or by author.
Traditionally, we’d come up with a way to use our categories and post tags to have some sort of classification system. I’m going to show you how you’ll be able to break free from this rigid system and do things your way.
In WordPress 2.3, the new taxonomy API was introduced. It allowed us to make up our own taxonomies. Here’s the problem: No one has been using custom taxonomies.
In WordPress 2.8, creating custom taxonomies won’t even be the job of a plugin developer. Average users can make and use any taxonomy they want with a few lines of code. WordPress will handle the rest by adding the meta boxes on the write post page and new admin menus for managing them.
What is a taxonomy?
I realize that word may be unfamiliar to many of you. In short, a taxonomy is a way to group items. Here’s the Answers.com definition of taxonomy:
- The classification of organisms in an ordered system that indicates natural relationships.
- The science, laws, or principles of classification; systematics.
- Division into ordered groups or categories.
The third definition is probably the best for our purposes.
By default, WordPress comes pre-loaded with three taxonomies: category, post_tag, and link_category. The first two allow us to label our posts a certain way. The last lets us categorize our links. I’ll be showing you how to easily create your own and use them in this tutorial.
Each taxonomy has what are called terms. For example, all of your tags are actually terms that live within the post_tag taxonomy.
What the new taxonomy features do
Once you’ve created your new taxonomy, WordPress will set up admin panels for you automatically. You’ll also get a new meta box when writing a post. This is the part that makes the new features in WordPress 2.8 so cool. We’re going to be setting up three taxonomies in this tutorial: people, places, and animals.
You’ll see this when you write a new post:

Here’s the view of the admin panel for our people taxonomy (click image for larger view):
Some of you might have noticed the word “tags” in a few places on the page. I’m not sure if this will be updated in the future or if it can be easily changed.
How to create a custom taxonomy
I’m only going to cover the basics here for average users. Plugin developers can take this and do all kinds of neat things. Also, the new features in WordPress 2.8 only apply to tag-like taxonomies (non-hierarchical) for posts.
In this example, we’ll be creating three custom taxonomies: people, places, and animals. You can create as many or as little as you want.
Open your theme’s functions.php file or create a plugin file to work with. Add this code:
<?php
add_action( 'init', 'create_my_taxonomies', 0 );
function create_my_taxonomies() {
register_taxonomy( 'people', 'post', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );
register_taxonomy( 'places', 'post', array( 'hierarchical' => false, 'label' => 'Places', 'query_var' => true, 'rewrite' => true ) );
register_taxonomy( 'animals', 'post', array( 'hierarchical' => false, 'label' => 'Animals', 'query_var' => true, 'rewrite' => true ) );
}
?>
Breaking down the code
Let’s look at one line of the code we started with and break down each part. The taxonomy we registered for people looks like this:
register_taxonomy( 'people', 'post', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );
people tells WordPress what the name of the taxonomy is.
post tells WordPress what object type this taxonomy applies to. You could also make a taxonomy for pages or links if you wanted, but WordPress doesn’t do the cool stuff with anything but posts right now.
hierarchical means whether the taxonomy terms can be in a hierarchy (categories are hierarchical, tags are not). So, we set this to false to behave like tags and to use the new WordPress features.
label is the name of your taxonomy that you want to show up in things like the WordPress admin. (Note: This should be localized if you’re creating a plugin for public release.)
query_var lets WordPress know if you want to be able to query posts for things such as showing all posts in the people taxonomy about Will Smith. If you set it to true, the query variable will be the name of your taxonomy. This can also be any text string you want. We’ll keep ours at true for simplicity.
rewrite is whether you want WordPress to give you prettier permalinks when viewing a taxonomy page or archive. So, you could have something like yoursite.com/people/will-smith rather than yoursite.com/?people=will-smith.
Keep reading, and I’ll give you some practical usage examples.
How to create a tag cloud with your custom taxonomies
Let’s say you want a people cloud rather than a tag cloud. Well, we’d use our standard wp_tag_cloud() template tag with a few extra arguments. Place this code where you’d like to show your people cloud:
<?php wp_tag_cloud( array( 'taxonomy' => 'people', 'number' => 45 ) ); ?>
It’s as simple as that. All you need to do is set the taxonomy argument to the taxonomy of your choice.
How to list a taxonomy’s terms for each post
Maybe you want to show a particular taxonomy’s terms along with your post, which is common with categories and tags. In this example, we’ll show the terms from the people taxonomy. Add this within The Loop where you’d like it to show:
<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?>
How to show posts only from a specific taxonomy
Let’s suppose you wanted to create a custom page template or set your home page to show 10 posts with the term “Will Smith” (from your people taxonomy). Add this code before The Loop:
<?php query_posts( array( 'people' => 'will-smith', 'showposts' => 10 ) ); ?>
What? Did you think it would be tougher than that?
Create your own custom taxonomies
Taxonomies are no longer something that only plugin developers can create. It’s time for you to go out and explore custom taxonomies for yourself. Make something that is unique to your site.
I’m thinking of making a WordPress taxonomy for my blog since that’s pretty much all I blog about.
If you have questions or would like to see more practical usage examples, feel free to ask in the comments. It might even be cool to set up a big list of ideas for new taxonomies. There’s so much more we could do that I couldn’t cover in one tutorial. It might be worth writing another one if everyone feels we need it.
Remember, this tutorial is for WordPress 2.8, which is under development at the time of writing. Things could change by the time it’s released.


Excellent tutorial, thanks Justin.
On the wp_tag_cloud example above, is it possible to use more than one taxonomy so the cloud would include people & animals?
This is great Justin, thanks. One thing I have been curious about. Does it automatically add multiple taxonomy queries? I.e. mysite.com/people/john/places/canada
Dave Kennelly — Nope,
wp_tag_cloud()currently only takes in one taxonomy.Andrew — I’m not sure. It’s not something I’ve thought about, but I can see how it could be useful. We’ll just have to try this out.
Just reading about this stuff makes my head exploding with plugin ideas.
But searching the taxonomy.php I found no way to unregister a taxonomy. How should we write proper uninstall routines?
Thanks for the answer Justin, as I thought but just hoping this could be done in 2.8.
I’d also love to know how you get on with Andrews query. If I could have a taxonomy of something like City Name + 3 Bedrooms + 1 Bathroom automatically generated, I’d be a happy man…
Justin, great post! I’m intrigued. Could I use a date in the taxonomy?
For example, I’d like to display a post as an upcoming event posted on x day, but happening on y day, and sort by y.
I’m guessing this is possible if I code the date as text i.e. 20090506.
What do you think? Suggestions?
This sounds really useful but I’m struggling to find a reason to use it for any projects… perhaps I’m just not getting it all the way yet… I can see how beneficial it is from a dev standpoint however.
Thanks for the write-up – can’t wait to hear more about it from you
Thomas Scholz — I could’ve sworn there was an
unregister_taxonomy()function, but after taking a second look myself, I didn’t see anything like that. I wonder if it’s all that important though. One could simply delete all the terms if they didn’t want it around. I guess that would still leave the taxonomy in the database though.DaveK — My brain is fried today. I’ll have to think more about combining taxonomies on another day.
John Schultz — I suppose you could use a date or something like that. Maybe a taxonomy called Event might work out somehow. Every situation would call for something a little different, so it’s hard to say the best route to take without knowing exactly what your project entails.
Chuck Reynolds — Not every project would need a custom taxonomy. Many would work just fine with categories and tags. A taxonomy is just a way to group things by relationship.
I also think we’ve been conditioned to only think a certain way about how we classify posts. We traditionally mold how our content is shown or how we get content from the database according to the default taxonomies. We’ve been forced to use a particular system. With custom taxonomies, we can mold our taxonomies to fit our content, which is the way it should be.
Here’s another example of something with custom taxonomies. Let’s suppose you ran a website about animals (maybe for a pet shop). You want to make each species of animal its own taxonomy. So, cat and dog would be separate taxonomies. Whenever you wrote a post about dogs, you’d put in the breed of dog as a term under the dog taxonomy. Since there are 100s of breeds, it’s best to separate this from other animals.
Sure, you could separate this by categories and tags somehow, but custom taxonomies would give you more fine-grained control over how to organize your site, which can be helpful to both you and your readers.
Oh, and from a development standpoint, it is much more beneficial.
yeah! I am so proud of WordPress! This will be our next big feature!
This is the feature that is going to put wordpress leaps and bounds ahead of any other cms.
What is also great is — is that taxonomies now take on the same role as tags which means you can create templates for each custom taxonomy…
e.g
taxonomy-people
taxonomy-places
etc.
This puts you in control of structure and design and opens up Soooo, many more possibilities.
Jonathan
Steffen — Yep, the ability for any user to easily make their own taxonomies is big.
Jonathan — I don’t think I would ever need another CMS after this and if/when support for custom post types is added.
Yeah, I like being able to break the templates down. You can go even further with this:
I’m thinking of covering this in the next tutorial. Since I covered creating custom taxonomies, I should go ahead and cover creating the templates.
This was an awesome post! I’ve got a project where we’re managing a sidetable of property listings (hacking the business directory plugin). Thanks to you, I’m going to implement the tagging of these using the WP taxonomy framework… sweet!
This is certainly awesome, but until WP does the “cool stuff” for pages, this is pretty useless to my client work.
Great tutorial, Justin. Thanks!
Domain Development — Well, you’re welcome. Let me know when you’ve put your project together. I’d like to see how you’re using your custom taxonomy.
Bryan Harley — The new, cool stuff is the auto-generation of meta boxes and admin panels. Sure, this is easier for developers, but it’s really great for users that can only handle basic code.
The taxonomy schema has been around since WordPress 2.3. If you have clients, then I’m assuming you’re doing development work. You can use this stuff now for pages and not wait around to see if it’s implemented in the future.
Here’s an example:
All you have to do is build the admin page and add a meta box. It’s not too tough if you know your way around WordPress. You might even be able to tap into some of the auto-generation stuff for post taxonomies too, but I haven’t really checked that out.
Hope that helps and maybe sparks some ideas if you need taxonomies for pages.
Justin replying Harley: You can use this stuff now for pages and not wait around to see if it’s implemented in the future.
Now that`s even more interesting. I hope you too find some time to experiment with taxonomy for pages Justin, and maybe find something interesting to include in your series on page templates.
John Myrstad
I’m doing development work sure, just not too familiar with the customization of the admin side. How can I add the meta boxes and the new admin page?
John Myrstad — I don’t really have any ideas that I’d like to try with taxonomies for pages right now, but if I ever do, I’ll probably write a post on it.
Bryan Harley — Here’s the page for add_meta_box() and how to add admin menus. That should get you started.
Hi Justin,
I’m not using WP 2.8. But I have used the “Custom Taxonomies” plugin for 2.7.
Just wondering what would happen in the following scenario:
Let’s say there is custom taxonomy of say /genre/jazz
and there is also a category named /jazz.
What will happen?
Ray — I’m not sure how you want me to answer the question. Can you be a bit more specific as to what you’re looking for?
Learned exiting new things with your article. Thanks Justin!
Wow! This get’s me thinking of some amazing possibilities that might be accomplished with 2.8, but also starts to heart my head for thinking miles outside the box.
Jean-Baptiste Jung — You’re welcome. I’m really having fun with it, so much so that I’m already testing it out on ThemeHybrid’s showcase blog (see sidebar — browse by color).
The Frosty — The reason I like it so much is that users can make it personal to their site. They don’t have to use the same thing everyone else is using.
Pretty cool ! Found a new toy to play with ^^
Woof!
The hard part about taxonomies is “How do you use them?” and “What are they for?” I have been trying to read this month about “linked data”, semantics and “social media” to understand how to use these newer advances for making my small blogs/websites/social media where I design approaches for users. But, there is either a mass of weak information, highly advanced technical stuff or nothing. I am liking your approach more and more Justin. You nailed simplicity on the fuzzy ideas on taxonomies
I do not clearly understand the difference between tags and keywords. I understand categories are hierarchal but are they tags? I get categories are a taxonomy. Are keywords, tags, categories and meta-data better understood from the taxonomies point-of-view? Is this semantic web or lacking semantics? Would you call taxonomies linked data? Tim Berners-Lee in a rockin’ recent introductory talks on “Linked Data”
http://www.ted.com/talks/view/id/484
referred to the wikipedia page on Berlin’s data navigation box on the right as “linked data”
http://en.wikipedia.org/wiki/Berlin
This is important because in engaging “How do you use them?” and “What are they for?”, taxonomies like categories hold great potential for people like me who are organizing complicated content and trying to get it to sit up and bark.
Great post on taxonomies in 2.8. I read Ryan Boren’s post on WordPress 2.3 taxonomy schema features a few months back but at my age I remember little of it. Anyway, what I was trying to figure out then and now: is there a way to support multiple hierarchies within a WordPress taxonomy. In other words, can a term have multiple parents?
For example: if I have a category for states, and 50 states, and then each state in turn has counties. Or, a variation on Ray’s example above where I have a category for music genre, and then each genre in turn has an origin. In these two examples the terms county and origin need to have multiple parent nodes.
These are the sort of messy relationships we run into all the time in the real world. If WordPress could handle multiple hierarchies, that would be really powerful.
Many — I’ve been doing nothing for the last few days but playing around with taxonomies. They’re just so darn fun!
Don Spark — I guess I could see how what to use them for and how to use them could be tough. I think it really comes down to your blog. I think the real question is, “Would a custom taxonomy benefit my site?”
I think we need to break this down to the simplest form. We have taxonomies in WordPress. Both tags and categories are taxonomies, but the naming of “tags” and “categories” is arbitrary when you get right down to it. To me, custom taxonomies will allow us to be more semantic (though people will no doubt abuse what’s given to them).
Here’s an example of a custom taxonomy I’m using at the Theme Hybrid Showcase, which is used to show off modifications of my themes. I’ve created a taxonomy called “color” (see sidebar on the site). This allows me to group posts together by the color of the theme modification. This doesn’t really fit in under the tag or category taxonomies.
Taxonomies are all about grouping posts, pages, and other things together.
Sam — Great question. It’s something I haven’t given much thought to, but I can definitely see the usefulness in it.
I do think there’s support for something called “term groups,” which might offer something in the neighborhood of what you’re after. Unfortunately, there’s next to nothing on this in terms of documentation. And, I’ve seen message board threads where developers are confused about this. It’s definitely something I’ll look into at some point.
Great article!
Am I correct to say there is some overlap between taxonomy and custom field? Suppose I want to classify my book reviews by author and genre. I can create custom taxonomy OR add custom fields, right?
The only benefit of taxonomy that I can think of is the tag clouds. Other than that, what do you think the main advantages of using taxonomy over custom fields? And when should we use it?
Battra — No, there’s not really an overlap between taxonomies and custom fields. Granted, you could make a fake taxonomy by using custom fields, but it’s a rather crude way of doing things. Just ask yourself this, “What’s the difference between a category and custom field?” If you think about that, then you can probably see some major differences.
I suppose you could use either, but custom fields on different posts aren’t connected in any sort of meaningful way. For all WordPress knows (without you specifically writing functions to handle it), the same custom field keys on two different posts are meaningless.
Think of taxonomies as a way to give meaning and structure to your posts, pages, or links/bookmarks.
Here are some things you can do:
1) Visit a taxonomy archive.
2) Set up custom templates for taxonomies (i.e.,
taxonomy.php,taxonomy-people.php,taxonomy-people-justin-tadlock.php).3) Query posts for a specific taxonomy.
4) List taxonomy terms (sort of like you list your categories).
5) Use them within your post area in addition to or to replace the default taxonomies (i.e., categories, tags).
6) Taxonomy term clouds (like a tag cloud).
7) Do anything else you can already do with categories and tags with new taxonomies.
And, that’s just the tip of the iceberg. Theme/plugin developers can really go wild with this sort of stuff.
There’s no advantage. They’re just two completely different things. Custom fields are for adding additional information about your post that you can’t do with the tools already available. Taxonomies are for connecting your posts together by relationship.
I hope I’ve explained this well enough now that you can see the differences between the two.
could these new taxonomies be applied to users? thinking about advanced user accounts (with additional fields) and organizing people by one or multiples of categories via certain fields…
Chuck Reynolds — I suppose you could have a taxonomy to be able to organize users, but I see little point in it. WordPress already has a robust role and capability system for that sort of thing.
Ah, it’s much clearer now! Thanks for going to great lengths to explain this.
Hey Justin, thanks for the documentation on the new taxonomy stuff. I’ve been waiting for this new UI for taxonomies for a while now, but it falls short of my expectations by not providing a ‘category’ like, hierarchical UI for adding and editing new terms to each taxonomy. The category hierarchy is why people are using them as pseudo taxonomies in the first place, because they are hierarchical and you could see all your options right there in category list.
Is anyone else looking for that kind of functionality and would be willing to collaborate on building a plugin for it?
johnathan.andersen [at] gmail.
Johnathan — It’s hard to believe something like this could fall short of anyone’s expectations. I would never expect something like this in core. The functions and capability to extend this have been in WordPress since 2.3. I figured the devs are just helping push some of us along to make bigger and better things by providing the automatic stuff as an example.
If anything, this greatly exceeds my expectations.
Alright, I understand how it exceeds expectations… but when I expected the to behave like categories, I was disappointed when it ended up like tags. (Granted I only found out about the implementation when the beta was released.)
I think the main benefit of a category-like implementation of custom taxonomies and terms is the elimination of long category lists of multiple parent/child relationships (that often try to do what custome taxonomies could do more easily). Like the current ‘tag format’ implementation, you could keep taxonomies separate, but have the benefit of seeing all of your ‘predefined’ terms for each taxa. Because I work on a lot of WP – CMS sites that are run by teams of editors, it wouldn’t be helpful to the authors to have to remember which terms were ‘allowed’ for each custom taxonomy. And as was said above, because the custom field implementation can be rather wonky, the built in permalink structures and archives of taxonomies is an added bonus.
Because I can’t build a plugin of my own that adds that particular UI, if anyone would to like work with me on building a taxonomy/category UI plugin, please feel free to contact me.
Am i right, that the hierarchical custom taxonomy isn’t working yet? When i set ‘hierarchical’ => true, it doesn’t show up..
But yes, it’s really a nice feature, that i’ve been looking forward to. This is the only thing i envied of drupal (which was able to do custom taxonomy for a while now)..
Omar — No, hierarchical custom taxonomies have been working since WordPress 2.3. It’s not working in the sense that WordPress will automatically add meta boxes and admin menus for you.
Didn’t try it out since it’s crossed my mind just now but I guess it also can be displayed by using your WordPress Template Tag Shortcodes plugin. Just by adding the right argument to [wp_tag_cloud]. Or can’t it be ?
Hi Justin
and explain it so simple
thanks for this information
it works like a charm in the administration panel but all links are error 404
permalinks are: post_name id
category base is default
rewrite is true is set by the *action*
what can I do to get them work?
do you have any ideas?
thanks
Monika
oh my dear Justin
so sorry for this double comment
it doesn’t work for me with WP 2.8 beta2
but it works with the latest nightly building
I will play with this a little and than write an article in German language – credits to you is *deafult* by my articles
Hi Justin, Thanks for posting this excellent information.
I’m really only just beginning to get my head around this – perhaps you could point me in the right direction?
I have a site that has 4 different wp installs on separate subdomains.
All the wp installs are based on the same topic but are different functional areas. e.g. news, interviews, product reviews.
I’d like to tie the tags from each subdomain together so that they could be referenced from any of the 4 installs. So that if someone was reading the news they could click a tag that referenced interviews on the same topic.
I hope I’m making sense. If you could point me in the right direction I’d really appreciate it.
Apologies for the long post.
Thanks
Paul
Justin this is exactly what I need. Thanks!
How would we call this as a function in our child theme’s function.php?
– for instance I want to use the conditional tag if ( in_category( ‘discs’ ) …
I was able to make this work thanks to your tutorial on creating custom post templates.
Thanks again – this is perfect!
Arrived here following a tweet by ‘Yoast’ and I have to say this indeed sounds very cool. I actually was planning on how to implement a more structured backend for one of my newer projects about cars.
This make it so much easier when picking tags and sub-sorting cats.
Thanks
Donace
Sounds like a great feature – thanks for the write-up.
I do have one question about your code, specifically the create_my_taxonomies() function. If I understand it correctly, the function will run every time the site is loaded and call the register_taxonomy() functions. I would guess that this is only something you’d want to happen once?
Am I mistaken, or does the register_taxonomy() code deal with ignoring duplicate request? I also wonder what kind of overhead this adds.
WordPress opened the possibilities of adopting it in any kind of system EASILY (put emphasis on easily). With it, the origination of the posts will be better now.
Apart from that, wordpress has increased competition for Drupal which is another amazing but heavy CMS. Drupal is still a bit easier because you don’t have to add any line of code to bring up meta boxes but I hope that one day WordPress will add an easier way to add meta boxes just like Drupal and Expression Engine.
Many — I haven’t tried it out with the Template Tag Shortcodes plugin yet, but I should be updating it shortly after WordPress 2.8 is released. If it doesn’t work now, it will in the next update.
Paul — You’ll likely have to hire someone to custom code something like that. Maybe wait around until WordPress and WPMU are merged. Things like that should be easier.
amy gail — You’d have to create your own functions to have the equivalent of
in_category()for your custom taxonomies. It shouldn’t be too tough. Just copy the same code used for tags or categories.Donace — I’m glad to hear you might be able to use it. Let me know if/when you get your car project set up.
Eric Martin — You’d actually want it loaded on every page view. Although running it once will create the taxonomy in the database, it must be loaded on every page to use the taxonomy-specific functions regarding your taxonomy.
Haris — Along with this and (possibly) better support for custom content types in 2.9, WordPress will keep eating away at the competition in the CMS market, especially if it continues to stay lightweight.
Justin,
I noticed you mentioned (on the Series plugin post) releasing sometime into the future a plugin for 2.8 that can manage custom taxonomies. Do you have a rough timeframe for this?
Thanks alot! This will power the magazine-style sites on Wordpress without the annoying custom fields.
And this tutorial rocks.
Paul — I’m not sure. Right now, it’s in the very early stages, and I need to update all my other plugins and themes for WordPress 2.8 first.
I do have some ideas though, so I’m hoping I can get something out in the next month.
z0r — Yes, there are some uses that have traditionally been done with custom fields that can replaced.
Don’t dis my custom fields though! They have a lot of great uses.
I wonder if defining the taxonomies in the function.php of a theme is not a wrong choice… It would be better to define them on the “admin” side, not on the “view” side. I’m wrong?
I still confuse what this things for..
What the difference with common tag??
Did you mind that this is the categorised tag?
Hello, this is a great tutorial. I am really happy to find more taxonomy functions in WP. Looks more and more like a full-featured CMS.
I managed to create some taxonomies (tags) with you tutorial but I can’t find how to create more taxonomies (categories).
I thought this code would work :
register_taxonomy( ‘rating’, ‘post’, array(‘hierarchical’ => true, ….);
Why “hierarchical=true” doesn’t create categories ?
Hi Justin!
Thanks for this inspiring article. I’m now asking myself how I could use these new taxonomies (e.g. people and places) to tag photos (inside galleries).
Any ideas?
WordPress 2.8 came out at the right time. I have a great use for taxonomies on this real estate site.
Playin’ around with all this on WP2.8—working great so far. But I wish there was a way to move specific tags to the custom taxonomies, (eg move “africa” tag to the “places” taxonomy). Integration into the edit post listing section would be great too. Plugin developers Go!
“Here’s the problem: No one has been using custom taxonomies.”
That’s not true at all. There are and there were plugins that help to use the incredible power of custom taxonomies before. I’m using such stuff on my own quotations page, and just finished a magazine, that uses plenty of custom taxonomies
By the way, your article is great
Satollo — Defining them as shown in the tutorial would be the correct way to do it.
Adi — Maybe you should check out this post I wrote on how I used taxonomies to create a movie database. It might explain it better.
Nicolas Mollet — Hierarchical taxonomies are created with the code you posted, but the automatic meta boxes and manage screens aren’t handled by WordPress right now. You should post a feature request for this on Trac.
Nick — I have some ideas about this that I want to touch on at a later time. Let me get back to you on this one.
Haris — Doing a real estate site would lend itself well to custom taxonomies. I could see lots of uses with that.
John — I just mentioned to someone a few minutes ago that the ability to move taxonomy terms would make for a great plugin. I’m sure we’ll see something like this in the future.
DjZoNe — It is entirely true. “No one” is not meant to be taken in a literal sense. I can name the number of people I know using custom taxonomies since WordPress 2.3 on one hand, and one of those people is me. You’re just one of the few exceptions to the rule.
Thanks for the post, Justin.
I have problem to categorize my tags and keep related posts connected in some ways. This feature might be a clue to solve my problem. I need to try it to see how it works. Hope new gadgets coming soon:)
JoeNo1 — It has definitely made things easier for me on a couple of my sites. Maybe it’ll allow you to organize things better.
I created a ticket “register_taxonomy only for tags, not for categories ?” for a new taxonomy feature
See http://core.trac.wordpress.org/ticket/10122.
Thank you Justin for your answer.
I’ve got an established blog with a whole load of tags, some of which would be better off as part of a custom taxonomy now it’s available – is there a way of converting them? (I’m OK with going into PHPMyAdmin)
@Mary-Ann Horley: I guess you’d have to 1. get the IDs of the tags you want to reassign (from wp_terms). 2. go to wp_term_taxonomy, search for those IDs and then set ‘taxonomy’ = ” (like ‘places’) for all of them.
Nicolas Mollet — Cool. Looks like Ryan posted that it would be something they’ll do in the future. I’m hoping it’s sooner rather than later.
Mary-Ann Horley — With the number of people starting to use custom taxonomies, I imagine, we’ll see some type of taxonomy term converter in the near future from someone. If you try out Omar’s suggestion, let us know how if it works out for you.
Great article, thanks very much for putting me on to something I never knew existed in WP.
One question…
How do I use this with conditional tags?
For example, I was using has_tags() to display certain text on single.php if a post has a certain tag.
Now I’m using custom taxonomies, this no longer seems to work.
Anyone know how I would do this?
Thanks!
Alex —
has_tags()should not work because that’s a function that deals with tags. You’d have to write your own conditional tags for your taxonomies (It is custom, right?).So, you’d create functions like
has_people()orin_places(). Look at how it’s done for tags and categories in/wp-includes/category-template.php(version 2.8).Hello!
How can I see all my tags in on taxonomy? Is it possible?
In this case I won’t need anymore the plugins like Simple tags or WP Existing tags
Justin – Thanks for your reply.
I’m slightly confused how I would make a custom conditional tag. I’ve looked in wp-includes/category-template.php (ver 2.8) and am none the wiser.
Could you possibly give me a little guidance as how to create custom conditional tags?
Thanks in advance.
What a great post. I saw this a few months ago but now I have 2.8 and a new (second) website that uses Wordpress.. and I have a great use for it. Thanks!
Anton Borisov — You can use the
wp_tag_cloud()function for listing all of your terms (not tags) in a taxonomy.Alex Capes — That was my guidance. I don’t know any more about it than you do. I’d have to sit down and dig into files, write code, and test it just like you would.
Shane — Cool. Let us know how you use your custom taxonomies.
Justin – Is it possible to style the css using taxonomies? For example:
That would work for categories. Is it possible to do similar with taxonomies?
Thanks for the great introduction, Justin. Question: You focus on non-hierarchical taxonomies. I’m working with a client who wants multiple taxonomies: food, wine, beer, spirits, that are mixed hierarchical and non-hierarchal Wine>color>geo region>appellation>vintner>vintage and who would love a multiple field search. Taxonomy support in 2.8 gets us closer, can she get what wants?
Great tutorial Justin! Having the possibility to use custom taxonomies is a lot useful for the kind of “directories” I intend to make with wordpress.
I am writing to let you and your readers know about a package I’ve assembled to make it very easy to run a wordpress installation in a portable fashion (usb pen or local drive), for testing and development purpouses of course! If you’re interested check it out at http://nunoantunes.com/wordpress-portable
Hope some of you guys find it useful. Thank you Justin for sharing a lot of knowledge about wordpress.
Thanks for the tutorial, Justin!
What if you’ve got one post per tax, assigned this tax to other posts, display this tax’s URL on the posts that belong to it and want it to link to that single post?
For example, you’ve got a handful of cities that are located in a certain region. You gave that region a tax and, in turn, tackled that tax onto all cities located in that region. Now you’d like to display that tax’s URL in the sidebar of the cities’ pages in order to link to the region’s page (that is, *without* the tax’s word in the URL; i.e., -> domain.com/region instead of domain.com/regions/region).
How would you go about doing this?
Justin – great breakdown as usual!
In your Will Smith query_posts example, how would you get all posts filed under ‘People’ using query_posts?
Excellent article. Thanks Justin.
Thomas Scholz wrote above:
And you answered:
As you point out, there is no unregister_taxonomy, but it is not necessary. Just removing the code in function.php gets rid of the taxonomies. However, is any terms were entered, they remain in the DB.
If I did use something like
'will-smith', 'showposts' => 10 ) ); ?>in my theme, can I correctly assume that it will keep working even if the register_taxonomy lines of code were removed from functions.php ?Sorry, this ”
'will-smith', 'showposts' => 10 ) ); ?>” got cutoff in my previous comment.Hello Justin,
I’m trying to understand how can I do a sub-taxonomy, and I saw this:
“hierarchical means whether the taxonomy terms can be in a hierarchy (categories are hierarchical, tags are not). So, we set this to false to behave like tags and to use the new WordPress features.”
So, if I understand well, a custom taxonomy can be hierarchical, but I don’t understand how to:
1- use it anyway as a post “tag”
2- define a sub taxonomy.
For example, if I work on magazines, I may have several names, and issues.
Mag1 – Issue 1
Mag1 – Issue 2
Mag1 – Issue 3
Mag2 – Issue 1
Mag2 – Issue 2
Mag3
Mag4 – Issue 1
but if I do something like that:
but i don’t what to put in XXXX as it should apply on posts, but be a sub taxonomy of magazine…
What could be the solution?
Shane — You’ll have to create your own conditional tags for custom taxonomies. Check out the post I made on this in the WordPress.org support forums.
Marilyn Langfeld — WordPress 2.3 introduced the taxonomy system as it is today. You’ve been able to create an manage hierarchichal and non-hierarchical taxonomies since then. WordPress 2.8 just does all of the work for non-hierarchical taxonomies. You’ll need to build the management screens and meta boxes for your client if she needs the hierarchical type.
WordPress Portable — Looks interesting. What does it have to do with taxonomies?
Marcus Hochstadt — You’d have to tinker around with the
wp_rewrite_rulesfor something like that, which isn’t really my area of expertise.David Williams — I think you’re coming at this a little backwards. That’s like asking how to query all posts that are in a category or all posts that have a tag. “People” is just another word for “category” or “tag” in this instance. Traditionally, we’ve used arbitrary labels like category and tag. Custom taxonomies just give the labels more meaning. It’s the terms within the taxonomy that you’d query.
Guillermo — As for a missing function to unregister a taxonomy, that’s only true with custom taxonomies. Remember, WordPress is packaged with three taxonomies out of the box.
Your custom query should not continue working if you removed the taxonomy.
Sat’ — To answer your questions:
1) If it’s hierarchical, it can’t be used like a tag. Tags are non-hierarchical.
2) You’d need to set
hierarchicaltotrueinstead offalseto have something like that.Either way, hierarchical taxonomies are outside the scope of this tutorial.
Justin ,
am pulling 3 external feeds
Team Betting information
Team Shirts for sale
Team matches upcoming..
I know tags is the way to pull all together but not sure how to integrate external data to these..
Any pointers? Data is outside of wp tables…
Great post, as always.
Is there any way to reorder the list of custom taxonomies in the admin page? (say by the slug or something…)
@Justin Excellent tutorial — I was able to experiment with this on my local install and it works great. A few questions (as if you haven’t answered enough already):
1) The WordPress function reference doesn’t explain what the parameter “hierarchical” does. I set this to “true” to see what happens, and it has the effect of hiding that particular custom taxonomy item from the “Posts” menu, but seemingly nothing else. If tags cannot be hierarchical, then what does this parameter do?
2) You mention to ‘Sat in
http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28#comment-134923 that “hierarchical taxonomies are outside the scope of this tutorial.” Will you eventually write such a tutorial, or can you point us to a good one?
3) Using your examples:
yoursite.com/people/will-smith
What can be done to display content when people visit “yoursite.com/people/” (the root of the above example URL)?
Thanks!
goalpost.tv — I’m not entirely sure what external feeds have to do with taxonomies.
kucrut — You’d have to hook into the
wp_tag_cloudfilter hook and change theorderand/ororderbyarguments, but you’d only want to do it on the admin side of things for that particular page.Spamboy — Yep, loads of questions. I didn’t realize this would be such a popular post.
1) The
hierarchicalparameter allows you to have a hierarchical taxonomy, which is like what you see with the default category taxonomy. Tags (and taxonomies like what’s shown in this tutorial) are non-hierarchical. Unfortunately, WordPress doesn’t automatically add the meta boxes and manage screens whenhierarchicalis set totrue, but I think this is planned for a future release. However, the taxonomy itself is still created.2) I might eventually write a tutorial on hierarchical taxonomies, but it’s not something I have planned at the moment. As far as I know, there are no tutorials on doing this (as in building the meta boxes and manage screens).
3) You can create a page (WordPress Page) like
yoursite.com/people. I recommend usingwp_tag_cloud()on that page to show a term cloud for that particular taxonomy.@Justin One of the largest reasons this post is popular is because there’s not a wealth of information beyond this blog on custom taxonomies. That, and it was well-written and concise. A few followups:
1 and 2) So even though WordPress doesn’t automatically provide the meta boxes and manage screens, it still supports custom hierarchical taxonomies, correct? Or are the only such taxonomies available are categories delivered out-of-the-box (OOTB)?
3) Thanks! Right after I posted this, I played around with it and stumbled upon that trick
Thanks for this tutorial.
I want to delete the posts and categories taxonomies from a set up I am doing right now, and create very specific taxes in their place. I want to delete these two functions from even appearing in the backend, so as not to confuse my authors unduly.
As you say, post tags and categories com ‘reloaded” is there a way I can unload them?
meant to say “come preloaded,” sheesh!
Justin, just playing around with a custom taxonomy for my girlfriend’s site and having some minor issues… I know this isn’t really a support thing, but I’m really hitting my head against a wall trying to figure out what I’ve farked up…
Feel free to ignore this, but I figure if I don’t ask I’ll just get MORE frustrated, lol.
Setup a page to list all posts in a taxonomy (in this case beauty): http://geekyhealth.com/beauty/ (ignore the domain, it’s a test blog for doing her new design)
registered taxonomy:
Page just has simple code:
To me, this should show all posts with “beauty” as the Subjects… but it shows ALL posts, in like chronological order or something? Kinda weirded out as to why though…
Justin,
You did not just start a ‘popular post’ – this is an idea who’s time has come and you have ignited the dry timber in a large forest.
A quick question if you have the time. I have installed the 2.8ish trac of wordpress mu and thus am able to see the custom taxonomy meta boxes.
What is the best coding practice to use for wordpress mu in functions.php so that custom taxonomies are not registered for every blog and can be targeted specifically to the relevant blog ?
Alex.
probablepossible — Unfortunately, there’s not an
unregister_taxonomy()function. We were discussing this earlier in the comments. Right now, all I can recommend is having your authors hide the meta boxes for categories and tags for the post editor.Jeremy Wright — First, I should ask: Why not simply link to the Beauty taxonomy term archives? I’ve never quite understood why people create new archives with pages when these already exist. People do this with categories all the time too.
Your query should look like this:
Make sure you’re using the slug and not the name of the term. When registering your taxonomy, you can also set
query_varto the exact thing you wantsubjectsto be when you query posts.Alex — I’m not really that familiar with MU, so I can’t say for sure.
If you add a plugin, does it automatically load for every user or can individual users choose the plugins they’d like to use? If the latter, I’d just create a plugin and activate it only on the needed blogs.
Justin,
Thanks for the quick response. I had tested it by just dropping the lines into functions.php, thus was activating for every blog in the mu environment. I have created some code in there to register taxonomies based on the blog.
However, the best idea would be to develop a plugin that can be activated, but more importantly allowing the admin to configure the taxonomies.
Creating a plugin to add custom taxonomies is a stretch on my technical skills, please let me know if one has been developed. I would expect that the custom taxonomy manager plugin would work on mu with and am happy to test.
Kind regards,
Alex.
Hi Justin, really interesting article. I’m wondering if you can search for items within a specific taxonomy?
Basically I am using pages for products on one of my sites and would really like to be able to search my products but nothing else. Would it be possible to have a products taxonomy, and from that a search box where I can search for a specific product?
Thanks.
Alex — I’d like to build a plugin myself. I’m kind of debating whether I should wait for better support of hierarchical taxonomies from WordPress though.
Mitch — It’s entirely possible, but you’d have to have someone build it for you. It’s not something you’ll be able to easily do.
This sounds really useful but I’m struggling to find a reason to use it for any projects… perhaps I’m just not getting it all the way yet… I can see how beneficial it is from a dev standpoint however.
Thanks for the write-up – can’t wait to hear more about it from you
Hi,
I’m contemplating to change a category based “multiblog” setup to a taxonomy based “multiblog”. There’ll be a mandatory “blog” taxonomy switch on the edit post screen (and possibly on the manage posts screen as well) – so I’m wondering about replicating the current category based URL structure in the setup and I am wondering if it is possible to use other taxonomies than categories in the permalink setup –
so
/%category%/%postname%/
could be replaced by
/%taxonomy-abc%/%postname/
Is that supported in the current taxonomy setup? Thanks for a brief reply!
@An33k Here’s an example of how I plan to use it, if it will help you picture a real-world application.
On my blog, I have stories that feature various characters and locations. Each of these will now become a custom taxonomy, which allows me to customize tag templates to display character bios, location descriptions, photos, etc. whenever someone visits the custom taxonomy’s tag pages.
For example, one character is my wife Jenn. Since my taxonomy will be called Characters, her page will reside at http://spamboy.com/characters/jenn. Then, whenever I write a story featuring Jenn, on the Post Edit page will be a Characters box where I can enter her name and have it automatically associate with the custom taxonomy (vs. the generic list of tags).
Doing this allows me to logically group my tags, then permits me to use the delivered tags (those without a base grouping like “Characters”, etc.) in the future as I see fit without being bound by how I used them for other things like Locations.
Did this make version 2.8 I can’t seem to find any reference to it on the wordpress.org site?
Sounds ideal.
Thanks for posting.
Ian.
An33k — I see this as being more beneficial from a user’s standpoint than a developer’s. Sure, it makes things easier for developers, but it doesn’t really add more than we already had since WordPress 2.3. It’s more useful to users since it puts the power into their hands by giving them the ability to create custom taxonomies that work solely for their site.
This may not be something needed for every project though. If you’re looking for a real-world example, read my followup post on how I created a movie database with custom taxonomies.
ts — I’m not sure if you can set up your permalinks like that. Well, it’s likely possible, but I don’t know how that would work. I’d say take a look in
/wp-includesand find how it’s done with categories.Ian — Yep, it’s in there. It’s listed on the Version 2.8 page. This tutorial is pretty much the only documentation you’ll find on the feature though.
Hi Justin
I’ve been reading your guides over and over and over again.
I can’t find anywhere to get support on this subject so im trying here.
I keep getting “not found” and a search box when i click on my taxonomies.
I don’t get any 404 so i must be doing something right but when i click the taxonomy it doesn’t show the posts.
Can you help me ?
Never mind – i found out that it did not work because i had Simple Tags plugin installed.
So anyone who can not get this to work for days – uninstall that plugin !
Sorry i meant the Category Visibility-iPeat Rev
Disable that plugin if your taxonomies doesn’t work.
Christ, I’m such a spammer here – sorry bout that !
Thanks for the article, Justin. It solves problem (of my own making) which I’d just encountered.
I’m building a family tree / history web site, and I’d wanted to ‘tag’ people by surname, country of birth and anything else I feel like. I cn do this, but then there’s no way to extract a list (or cloud) of only the surnames, only the countries, etc. So hurrah for custom taxonomies!
Gary
@Justin If this tutorial contains information not found in the documentation, would you consider updating the Codex to include it?
I have been trying to find ways to link to posts via taxonomies, like you would normally with permalinks and slugs etc.
http://codex.wordpress.org/Function_Reference/register_taxonomy
I found that but am not able to put it to any use?
Justin,
I think I may use this plugin
http://kpumuk.info/projects/wordpress-plugins/scategory-permalink/
as a starting point. The plugin allows the use of a main category
(/%scategory%/%category%/)to be added to the URL in front of the standard category. So if I query the custom taxonomy element the post belongs to and add it instead of the main category, the code should work. I think the magic starts here -http://codex.wordpress.org/Function_Reference/WP_Rewrite
Still, I need to dig deeper into this, will paged navigation work within custom taxonomies like it works within categories?
Cool, this actually works -
using the “Custom Taxonomies Plugin” I have created a custom taxonomy called “blog”, containing four distinct terms. I then modified the scategory-permalink plugin code to query which “blog” the post belongs to and get the according taxonomy slug using this code -
I then pass
$blogon to the scategory plugin as main category and can thus use its/%scategory%/rewrite variable, but it’s probably best to eventually rewrite the relevant parts of that plugin for this purpose.Maybe this is helpful for someone also looking to have a taxonomy based main Permalink structure.
knat simon — The WordPress support forums is where you’d go for support (in case you were still wondering).
Gary Taylor — A family tree/history Web site sounds cool. I’d love to take a look at how you’ve set everything up.
Spamboy — Honestly, I’m too lazy (and too busy most of the time).
I did just notice that someone has finally put up a register_taxonomy() page.
Shane — I’m not sure what you mean. Are you trying to list posts from within your
taxonomy.phptemplate and have them link back to the single post?ts — Yep, paged navigation works with taxonomies just like any other archive-type view.
Justin,
I’m currently using a plugin for taxonomies, actually just beginning to test it. I generally prefer to add features to the child-theme (hybrid based of course) instead of a plugin, if I can. I just prefer to be as plugin light as possible.
Above, you said “Open your theme’s functions.php file or create a plugin file to work with.” I’m curious to hear what your opinion is. In regards to site performance, is it better to add it to functions.php or use a plugin, in this case?
Part two of my question is, the plugin is simply giving me easy access to registering the taxonomy. I believe this is true because once I created some taxonomies, I can now add them to an asside via the “tags” widget (which should really be renamed now). If I keep the plugin for now, and opt for the theme inclusion later, I shouldn’t lose any work, correct?
Justin, when I get the site suitable for other people to look at without falling about laughing I’ll post to the WordPress forum. I don’t do things by halves, so I want it to be pretty perfekt before letting it loose.
Gary
This is an awesome tutorial.
Is there something similar to get_the_term_list but in a way that doesn’t output the results as URLs?
I would just like the actual term names for a specific taxonomy that are associated with the post.
Hopefully someone can help out! I’m so close to achieving my desired functionality.
Gary — It doesn’t matter if you write a plugin or use a theme’s
functions.php. The performance of your site won’t change. With that said, some plugins/themes are poorly written and can hurt performance.Your custom taxonomies are saved in your database, so your work will always be there.
David — You can use the
get_the_terms()function to grab an array of the terms.Hey Justin, thanks for getting back to me so fast!
I can’t seem to figure out how to use get_the_terms() properly.
I tried:
$values = get_the_terms( $post->ID, ‘location’); echo $values[0]
But nothing gets echoed in the post even though the particular post does have a term for the location taxonomy.
I’m probably missing something basic here… See any obvious mistake?
On the subject of “hierarchical taxonomies”:
I think there might be some confusion of terminology here. It seems to me that the “hierarchical taxonomies” that Justin is saying are available since 2.3 are taxonomy values (stored in the wp_X_term_taxonomy:taxonomy field) that apply to categories – it’s the categories that are hierarchical, not the taxonomies.
Yes, a hierarchical set of categories can use taxonomies, but without a taxonomy hierarchy how would you apply your taxonomy to your hierarchical categories? I think that in most cases you’d end up applying the same taxonomy to all your categories with a single hierarchy (all sharing the same root parent). This is really just using taxonomies as another level of hierarchy, and it might be more straightforward to not use taxonomies for that application and integrate the taxonomy as the root parent of the hierarchy or hierarchies.
For example, the breed of dog example in the tutorial would benefit from a hierarchy. Many current breeds of dogs are crosses of various older breeds. How might someone implement this example with a truly hierarchical taxonomy, and what would the benefits be vs. non-hierarchical?
Is it possible to create a hierarchical set of taxonomies and apply them to tags or categories? What is the best approach to achieve different types of functionality? I am seeing various ways to organize things, including this one (to put it in hierarchical terms):
- Terms
– Tags
– Categories
— Category hierarchy (via the wp_X_term_taxonomy:parent field)
and this one:
-Taxonomies
– Taxonomy hierarchy (als via the wp_X_term_taxonomy:parent field)
To implement a taxonomy hierarchy (or should it be “taxonomical hierarchy”?) the main hack is that the term_id would be empty or at least meaningless. Or would that be one trick here, to create a taxonomy (text) value that is also a tag/category?
OK, my mind is spinning on this one. I started out simply wanting to point out the two different concepts of hierarchical taxonomy here, but the possibilities are interesting, albeit complex and possibly confusing. I’m trying to sort out how to implement various features on my wpmu site (not public yet), and this term_taxonomy stuff is right in the middle of it. I’m pretty sure I want to stay away from term_groups, as they seem to be intended for term aliases, but the notion of a hierarchical taxonomy is what I need. I still haven’t figured out the best way to implement it, but this tutorial was very helpful in explaining the wp_X_term_taxonomy:taxonomy field in some detail and context.
After spending some time working with this here are some further thoughts on “taxonomy”:
1) The “custom taxonomy” concept here is one of two actual ways to implement taxonomies in WordPress. Both these mechanisms are implemented in the same set of tables (wp_N_terms, wp_N_term_taxonomy, etc.), and both have different advantages and disadvantages.
2) “Custom Taxonomy”, as described here, is a string-based (aka character-based or word-based) mechanism with only 2 levels. The parent is a string (or word), and the child is a Tag, which has a numerical ID as well as some strings (or words) as values. This type of taxonomy is useful when you want to lookup a flat (non-hierarchical) set of terms (tags in this case) by string (or word).
3) “Hierarchical Taxonomy” is a number-based mechanism, with multiple-levels. I say “number-based”, because in the database tables the parent/child relationships are defined by by ID number, not the Term name or slug. This is the older, Category Hierarchy, way of setting up a taxonomy. It is still a taxonomy, by the dictionary definition, in that it classifies a set of items and orders them. But it does not use the “taxonomy” field in the wp_N_term_taxonomy table to implement the hierarchy and taxonomy, thus some potential confusion arises in WordPress because of WordPress’s use of “taxonomy” as a specific database field (VARCHAR, 32 characters) that implements one of the two distinct taxonomy implementations in WordPress.
4) The concept of mixing these two types of WordPress taxonomies in a single Taxonomy in a WordPress blog seems like a bad idea to me. They are distinct mechanisms and have distinct uses. As I said in my previous post, using the “taxonomy” field (as described in the original tutorial) with hierarchical categories is messier than just implementing that parent value as the root of a category hierarchy.
Justin can probably translate what I just wrote into something less developer-oriented and more user/blogger friendly. I wanted to further clarify my thoughts about this after my long-winded post at the end of last week. I hope this all makes sense and clarifies things for at least one person out there.
Thank you so much for showing my how to do this, your guide is easy to understand and very well explained.
Justin, thank you so much for this taxonomie tutorial. I’ll try to use it in new Projects.
One Question. Is it possible to make a related toxonimie cloud.
e.g. when the user choose one tag of a taxonomie i like to show the related tags of other taxonomies by using wp_tag_cloud.
Hmm. Struggling here…
I’ve implemented custom taxonomies and had some reasonable sucess (trhough permalinks won’t work no matter how many flushes i try, plugins i disable or number of times I reset/save the permalink structure)…
I’m outputting a list of taxonomy tags at the end of a post, which output as links to /?taxonomy=tag.
The ‘tag’ page should surely list all posts which share that tag? Is there something I’m missing to achieve this?
Hi, thank you very much for you quick and easy guide to custom taxonomies.
I’m facing a little problem:
a) get_the_term_list outputs an URL and i want plain text, i need these values to create automatically a custom link.
b) Using the_terms() outputs looks like a total mess to me: i have quite basic programming skills and that array it’s way too much for my poor and cheap brain.
c) for example, i need to retrieve author’s name, “John Doe”, from custom taxonomy “author”: how can i get a simple “John Doe” output in simple plain text?
Best regards
@Zntgrg Try looking through the core file taxonomy.php — within that file are a bunch of delivered functions which may provide the functionality you need without having to do anything “exotic” like write a custom SQL query.
Ooops, forgot a reply!
@Jonathan Justin addressed that question of mine above (http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28#comment-136816). You’ll need to create a page whose slug is the same as your taxonomy slug, then modify it to show the tag cloud (or whatever other content you are seeking to display). I’ve got some code samples, if you need them, as I’m knee-deep in doing this myself.
Hi Justin, thank you so much for this post, I finally understand what taxonomies are about
Following chronicfarmers’ comment, I would like to know if there is a way to manage categories in WP 2.8 the way it worked before the implementation of taxonomies. I have the exact same problem as this guy : http://wordpress.org/extend/ideas/topic.php?id=2756 and we are not alone facing this big issue with WP.
WP doesn’t accept duplicate name/slug categories anymore, so how is it possible to use WP as a CMS? I can’t upgrade and if I do, I can’t make a dump of my database because all my posts belong to (multiple) different categories.
You seem to know a lot about how WP works, so maybe you’ll think of a solution. I don’t want to start over because WP decided to change things that may be fatal for my blog….
Thanks a lot, any help is welcome, I’m desperate…
Hey,
Is it possible to create a unique custom template for each taxonomy and serve this template to its related tags?
i want to love (and to be able to pronounce) “custom taxonomies” but i’m thinking ….
1) the content within is not searchable via WP search (including Search Everything type plugins)
2) Google XML Sitemap doesn’t generate anything from CT to help anything in the Google world
i did read that you can create a page w/ taxonomy slug, but doesn’t that detract from the massive SEO value that tags provide..?
@cracks:
1) true, although WordPress is expanding faster than the mundane search capabilities currently available. You should consider submitting this for a fix.
2) Google isn’t completely ignorant to your custom taxonomy content. Google already recognizes my custom tags — for example, I have a custom taxonomy of “locations” with the tag “bruce-hall” underneath it. Google found it easily: http://spamboy.com/locations/bruce-hall/
Comment afterwards: the custom Page for the taxonomy slug (ex: “locations”) is to provide something to display when the base taxonomy is being viewed. It doesn’t reduce the SEO value of the tags themselves (ex: “bruce-hall”).
oh i do (heart) WordPress Spamboy; it’s SO, CLOSE to being truly amazing.
1) i do have a big problem if the search issue can’t be worked around. Google have conditioned us to use search boxes. and where a site search doesn’t actually search all the content, it’s a factor many can’t / won’t compromise.
ie – go to the fabulous Pop Critics site and use the search box to search for “comedy” (or visit here where i’ve done it for you: http://popcritics.com/movies/?s=comedy). there must be a work-around for this surely..? visitors will only search once or twice and get “no results found” before moving on.
nb – i am aware that Pop Critics Search box IS a “search for movie” function, but when visitors see “search” and a search box, they don’t read labels.
@cracks I should have been clearer — WordPress search has always sucked, and has limitations beyond custom taxonomies. Therefore, there’s alot to fix besides just that element. I didn’t say it couldn’t be worked around — in fact, the best workaround is to install a plugin that overrides default search functionality, then personally modify that plugin to accomodate custom taxonomy searches; that way, you are not modify the core WordPress files. The ultimate solution is to submit a ticket to the WordPress team so that the core search functionality addresses that.
Excellent article !
I now consider implementing Custom taxonomies for one of my site…
Do you know if there is a link between custom taxonomies and custom fields ?
My site has posts with custom fields that I’d like to ‘convert’ into custom taxonomy.
Is there a way to do that other than doing it manually in the admin ?
Thanks for the great tutorials
David — You do it like this:
Just input all your values.
chronicfarmer — Nope, there’s no confusion of terminology here. “Category” is literally a taxonomy. It is a hierarchical taxonomy. Hierarchical taxonomies are fully supported in WordPress. There’s just no automatic insertion of meta boxes nor a manage screen for those types of taxonomies.
You are right when you say the hierarchy is defined by ID, but that’s just because it’s a lot easier to keep things safe with a number rather than other characters. Basically, the difference between hierarchical and non-hierarchical taxonomies is that hierarchical taxonomy terms can have a parent term.
Barny — You’re welcome. I’m glad you found it useful.
telebrain — Sorry, but I don’t understand the question.
Jonathan Alderson — You should stop by the WordPress support forums. There’s probably something wrong with your setup.
Zntgrg — Use
get_the_term_list()to grab the terms and usestrip_tags()to get rid of the HTML.Gregos — I didn’t realize something had changed in 2.8 with how taxonomies work, at least not at that level. You need to ask over on the WordPress support forums about that.
Avaz Ibragimov — Yes, you use
taxonomy-tax_name.php. I don’t know what you mean about related tags though.cracks — Taxonomies are more like metadata to content. Not the other way around. Your content is still searchable.
For your Google XML Sitemap plugin, the plugin author has had five major WordPress versions to integrate custom taxonomies. I’d find something better if it’s that important.
Lapinlove404 — You can write a custom PHP script to convert them for you.
Is there any way (yet) to remove the base level taxonomy from the URL ..?
So instead of this …..
popcritics.com/movies/genres/action/
the URL is …..
popcritics.com/movies/action/
I am considering using taxonomies to separate tweets that we will be doing on our site. Basically the tweets will be a separate taxonomy since they will be short posts. And for this taxonomy we will use a different theme layout.
Basically we will be doing a local version of our own twitter for ease of posting, and will use taxonomies such as “tweets” to make this section separate.
I do have one question, we don’t want these “tweets” to be passed on to our RSS Feed, but will have a separate feed for our Tweet RSS.. would this be possible, and how would we go about this. (I assume a plugin like Advanced Category Exluder would suffice?)
A second question is, if we use this taxonomy, do we need to choose a category as a default? Since it won’t really be under any category but in a separate taxonomy grouping by itself, will wordpress still subject a “tweet” to the default category?
I mean, why a post doesn’t necessarily have to have a tag to be posted, when adding this new taxonomy, will wordpress still go the default route and choose a category for me, even if I don’t choose one and go the route of a separate taxonomy (i.e. “tweets”)
Hello Justin,
I used added code given by you in function.php.Then i created posts with different custom taxanomy tags.Now after I published those posts tags were displayed but when I click on those tags it gives error 404 Not Found. Please help me with the stuff.
@Bhaskar
A simple “function flush” will fix it. Just go into WP Admin > Permalinks > and click “save”.
It’s a common problem, who’s cause is beyond me. But Justin addresses the workaround himself in another excellent Custom Taxonomy tutorial.
http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database#comment-146721.
@cracks thank you! i was having issues with a 404 error and your recommendation fixed everything for me!
i went into permalinks, did not make any changes from my previous settings, but pressed save and all is well in the world.
* link correction – http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database#comment-146721
(damn you period point)
one note and one qutestion:
you can also use taxonomy management using /wp-admin/edit-tags.php?taxonomy=post_tag (replace post_tag with your taxonomy slug)
question: i hardly need some sollution to have multiple parent categories. The problem is, that it is not possible, because of bug (IMHO) in wp_term_taxonomy, where id is unique, so you can’t define N:N structure.
I wonder if you know some workaround sollution
Having used quite a few different CMS’s I can say I love Wordpress, however Taxonomy isn’t something new. Drupal probably has the best Taxonomy system in the CMS business. However, due to it’s insane Learning Curve it is just not viable for the average user. Currently, I only use Drupal for Large Custom built sites and I personally use Wordpress for my sites and have recently began looking at is as a CMS.
Now the question I am arriving at with Wordpress’s new outlook on taxonomy is there the ability to filter results on a “Category” or “Tags” Template. For example, “Lets say you had a site that shows Games, and you wanted to filter the search using Taxonomy to grab only listings that were in two categories”
Here is what I am saying:
Category 1 (Parent Taxonomy Term)
Game System
- XBox
- PS3
- Wii
Category 2 (Parent Taxonomy Term)
Type of Game
- Sports
- Adventure
- Fantasy
Now is it possible to return a “Category Page” that displays only games that are:
Xbox – Sports Games
Filtering out the PS3, Wii, Adventure, and Fantasy Games?
If that is possible then would it be possible to display two loops with different results?
For example:
Category 3 (Parent Taxonomy Term)
- Best
- Worst
Then make it show the “Best” Games on top and the “Worst Games” Below?
I know this is possible with Drupal, but if it’s possible with Wordpress (without the major complexity of Drupal) I would definitely prefer to use Wordpress.
Thanks,
Tone
I am also eagerly awaiting an answer for Tone’s question. I am currently redeveloping my photography website, and would love to be able to have my images for purchase in a filtering system. Below is a scenario to work with:
Taxonomy 1: Formats
Standard, Panoramic, Horizontal, Vertical, Square
Taxonomy 2: Edition Types
Limited, Standard, Artistic
Taxonomy 3: Sale Type
Wall Art, Stationary, Stock Imagery
Taxonomy 4: Content
Landscape, Seascape, Abstract, Still Life, People, Animals, Sky, Water
Taxonomy 5: Colours
Green, Orange, Blue
(the list goes on)
Here are a few examples of the assignment of these terms.
Image A.
(T1) Panoramic, Horizontal
(T2) Limited
(T3) Wall Art, Stock Imagery
(T4) Landscape, Seascape, Sky, Water
(T5) Blue
Image B.
(T1) Square
(T2) Standard
(T3) Stationary, Stock Imagery
(T4) Still Life, Abstract
(T5) Blue, Green
Image C.
(T1) Standard, Horizontal
(T2) Limited, Artistic
(T3) Wall Art, Stock Imagery
(T4) Landscape, Still Life
(T5) Green, Orange
Is it possible to query the database from the previous array, thus narrowing the selection as the ‘terms’ are selected? Ideally a list of the selected tags would want to appear in a list with a ‘remove link’ to allow the user to step back and broaden the search again.
I know this is probably far fetched, but if anyone has any ideas, or could possibly do some custom coding I would be a happy chappy!
Hey Justin,
Great explanation on how to create custom taxonomy. I created 4 custom ones super easy with tag clouds on the sidebar for each and each post has 4 new fields with each one, but now I have problems displaying the results when I see the result page for one term of one taxonomy. Don’t know if i’m super clear here but basically in my archive.php page:
That only works for that specific taxonomy. I don’t get it how to just display the title of the taxonomy selected.
Then same problems to display related posts. It works with tags but can’t find out to make it work with taxonomy.
And same problem for my breadcrumb that doesn’t show anything.
If anyone’s got links where I can find answers then I would be more than happy to cheer with you about wordpress as a CMS but for now….i’m a little bit lost;)
Thanks
Chris
Just realize the code I pasted didn’t quite work:
Sorry if this has already been covered above, but can custom taxonomies be used in WP MU? I’m looking into ways to create a site for a non-profit that allows individual users to create their own campaigns to raise money for the organization. So an individual user could have one or more campaigns. Is this a possible application of custom taxonomies?
Thanks!
VERY useful tutorial, easy to understand. I honestly had no idea what taxonomy referred to prior to this article. Does anyone know of any current extensions that handle this sort of thing?
Hi justin, i dont know if want to auto description from this section.
if is category i can put auto description this :
pls helpme
Justin, great post.
One thing I can’t seem to wrap my mind around – let’s take your movie database as an example.
What if that site would be a media site. So, you’d write about movies, but also about. TV shows. In that scenario, many of the taxonomies (think genre, actors, director/producer etc) you defined for movies would also apply to TV.
How would you organize this without duplicating your existing taxonomies AND while maintaining slugs like “movies/actor/actor1″ and “tv/actor/actor1″
Any ideas?
@john
This could be accomplished by defining a different post type (getting some love in WP 2.9), but you are still limited to the ‘post’ format. Have a look at http://pods.uproot.us/ , a much better solution imo, one that I am currently working with. Now if you dont need that depth of structure, then reserve your categories (or define a new taxononmy of ‘format’ ), and then tag them that way. create sub pages for ‘movie’ and ‘tv’.
Hi Justin,
Is there a way to create a tag cloud that is not ordered by name or count. How could I create a tag cloud that is in order by when a member of the taxonomy is added?
hello I have an error:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘create_my_taxonomies’ was given in /home/www/xxxxxx/html/wp-includes/plugin.php on line 339
when I want display the tag cloud with my new taxonomie, there give me this error.
pls help. I need it.
@Rhys – thanks, I looked at PODS but I think it’s too much for what I am trying to accomplish. It reminds me of Drupal’s CCK and I still wake up in a cold sweat from that one now and then!
On another note – anyone tried tag clouds for custom taxonomies? I am having a problem that tags for unpublished (scheduled) posts show up in my cloud. Is anyone else seeing this?
Hi,
Im using the code blue revolution theme and tried to add code to my
functions.php file to create custom taxonomies.
Im getting a headers already sent error after saving the content. Any suggestions?
Here is the code:
Thanks.
Contact information removed. One should never leave personal information in comments.
You probably have two calls in the funtion.php file. It all has do be within one single opening and closing tag.
Thank you Justin for this excellent write-up, and kudos to the WordPress crew for implementing this. Great new feature. This feature saves me time, and allows me easier programming.
Just a tip:
In the the admin backend under ‘screen options’ (at the top right of the admin screen) one can choose to show which tags taxonomy to show in the post edit and write screen. Handy for example if only using custom taxonomies. Saves screen real estate.
+1 on the custom content types.
In addition it would be great if custom taxonomies would only show on chosen custom content types. Also it would be great if the custom content types will be able to be searched.
+1 on the ability to unregister taxonomies.
Hi there.
I’m trying to make use of taxonomies in my new blog. I’m also running a popular SEO plugin that automatically changes titles and adds meta information (description, keyword) to each post.
Unfortunately, taxonomies and taxonomy terms do not appear in my meta keywords. Only the category and tag terms appear. Can anyone point me to the right direction?
This code might be handy for some people. Although it might be that it could/ should be improved. This might not be the correct way to do this.
I was looking for a way to do this, as ‘get_the_tags’ appears not to work with custom taxonomy in tag.php. It will just get the normal tags. As stated above.
Based on the function reference ‘get the tags’ in the codex*. In tag.php this will get the custom taxonomy, and then match it against the current tag (so if your on tag url ‘apple’ it will only select ‘apple’ from the get_terms):
You might be able to do the ‘your_custom_taxonomy’ with a variable so it chooses the proper custom taxonomy automatically. Haven’t figured that out, yet.
* Url to codex entry function reference ‘get_the_tags’:
http://codex.wordpress.org/Function_Reference/get_the_tags
Original code:
Link to a piece of code that will automatically show the selected posts data for whatever custom taxonomy term page one is on.
See: Automatic post title loop in taxonomy.php
Code is subject to review.
I have got this error :
/wp-includes/plugin.php on line 339
Hi Justin!
I’m building a clasic list of posts and I want to add an extra information to each post on the list, based on displaying the value of one of my three taxonomies.
How can i code it?
I’m asking this to you, ‘cos I need the value saved in my BD not a cloud of values.
BTW I’m using SimpleTaxonomies Plug in.
Thanks in advance.
Jaume
Hey Justin I have solved my own question as you describe in your post of how to creat a movie database.
Displaying custom taxonomies in a post
Simply replacing taxonomy_name in the below code with the unique name of your taxonomy will handle that.
Thanks!
Jaume
I had no idea custom taxonomies was possible. This will definitely change the way I do things with WordPress! I am glad I stumbled across this.
I have 1000+ posts that have tags including people and topics in my database. I have implemented a “people” custom taxonomy, but is there a streamlined way to move the people-related tags from the general tag pool into the new taxonomy? I would even settle for a mass-edit sort of function similar to that seen in Simple Tags.
This would save me a LOT of work going through posts 1 by 1. Any input would be highly appreciated. Thank you.
Also, 1 more thing. When a term is clicked in a custom taxonomy list, the resulting page is a Wordpress “not found” page. I am not sure what the issue is, but I though making a custom taxonomy.php page would fix it, but I can find no templates for a taxonomy.php template. Any help would be MUCH appreciated.
Justin,
I am developing a new website using your awesome Hybrid (News child) theme and wanted to play with taxonomies. The website is about local information, such as real estate, communities, etc. One of the uses I thought would be interesting would be to create a list of related schools using taxonomies. The problem is that when I get the list (figured out how to hook it in to the Hybrid theme) it sends to a list of related posts. That isn’t so bad, but I’d love to also create a category for schools and when I add a post about a school allow that to cross reference communities (the posts about them) that the school services. When I create the taxonomy “schools”, I get a URL like this: http://website.com/schools/school-tag/. When I create a category named “schools”, I get the URL http://website.com/category/schools/. If I use a plugin to remove the term “category” from the URL, the taxonomies don’t display. However, if I create a post under the “schools” category using the same permalink as a tag, the post is overwritten by the new taxonomy, creating a page that lists all posts under the “schools” taxonomy tag.
Do you see how this is not working as I’d like? My goal is posts that are interconnected so that visitors can find more related information. Would I be better off just going with a “related posts” plugin, or can I use taxonomies to make this work somehow?
Ed
One other idea would be to create a custom taxonomies.php template for each new taxonomy allowing me to add information about the school and then announce a list of communities that are related. However, I am not sure how to do that using the Hybrid theme, particularly the child themes. (Still new to Hybrid, but loving it so far!)
Just a quick note incase it helps anyone else:
After following Justin’s excellent tutorials and also trying various plug-ins I’ve been trying to get custom taxonomies working for days. I could create the taxonomies themselves ok, and also create various tags or terms within those taxonomies but when clicking on a term to view it’s page (i.e. taxonomy.php) wordpress would always return a 404. Even stranger if a term closely matched a page slug I would be taken to that page! I tried fresh installs, refreshing permalink structures, removing adn re-creating tables in the SQL database, all sorts to try and get taxonomies functioning correctly.
Late last night I narrowed down the problem to a conflict caused by the Multi-page toolkit plugin. Since I’ve removed that my taxonomies have been behaving as they should. So if you’re getting frustrated by taxonomies producing 404s check your plugins! p.s. thanks for the great tutorials Justin!
I was wondering what WordPress taxonomies were… and then I stumbled on this post. Thanks for explaining it so well! Can’t wait til WordPress implements a feature so that hierarchical taxonomies will also have boxes added to the admin panel automatically!
This is not working for me in Wordpress 2.9 with the thematic themeset turned on. It works with other themes.
One of the best tutorials that i have ever seen. Thanks alot. I am creating a new theme and this post will help me a lot.
This post rocked my socks! Its just what I needed for a new project. Other solutions involved poking around WordPress files that would break everything when a new release came around.
one of the most helpful posts yet – and that is saying a lot because they are all helpful! one question – i was able to create a custom link taxonomy, but now can’t figure out how to list all bookmarks with a specific taxonomy. any ideas are much appreciated!
Justin – thanks. Really useful.
One thing I’m struggling with is how to get a list of other posts with the same taxonomy term as the current post. No related post plugin does it without specifying what term you want the related posts to relate to.
The scenario: I have a custom term ‘Author’ for a site that collects articles by different writers. There are hundreds of authors so I wanted to avoid setting up author-users for each one so turned to taxonomies. When the viewer is looking at an article by a particular author I would like to be able to display a list of other articles by that author without navigating away from that page onto a taxonomy archive page.
Do you, or does anyone here, know if that is possible?
Thanks again for the clear guide you have provided
Is there an update on the ability to move taxonomy terms between groups. Seems like several people are looking to do this. I really want to start using custom taxonomies but it seems there are still too many unkowns.
I’m intensely searching for the solution to moving taxonomies and the only thing I can come up with is to get into the database and edit the ‘wp_term_taxonomy’ table. It seems as simple as changing ‘post_tag’ to ‘people’ for example.
still waitin’ myself…
Hey. Ok, I found a sort-of solution using the “Simple Tags” plugin. It doesn’t let you move terms to a custom taxonomy but you can do a blanket search of all your posts and then add your terms to the taxonomy.
eg: install plugin > go to “mass edit terms” under the posts menu > select your custom taxonomy from the dropdown list at the top of the page > do a quick search > add your terms > click “update all.”
It’s not exactly ideal, I know, but it’ll get the job done until there’s an actual solution. Good luck /J
I’ve been using, and loving Custome Taxonomies since Justin published this post. But since upgrading to WP V2.9.1 the is_tax is causing grief (http://core.trac.wordpress.org/ticket/10721#comment:6).
And since CT’s are my primary navigation system, and I’m using if is_tax for custom page titles and descriptions, I’m a bit screwed.
Can anyone help?
Howdy Justin,
Great post mate, just wanted to pick your brains if you don’t mind. Soneone posted earlier about a need for event dates, and I have a specific need for a taxonomy related to this and I have no idea how to do it. Wondered if you could help.
It’s an events section where users can post a new event, where the event is going to be, a description, and when it is occuring.
My issue is the date.
I sorted the location with:
But I have no idea what to do for the date.
I want to ultimately display the day as a number and the first 3 letters of the month.
So event will be held on 7 FEB.
Is there a way I can set up 2 dropdowns, one for the day and one for the month, and set this as a taxonomy in the write panel for users?
I am quite new to this, hope you can help or possibly point me in the right direction.
Once again, cheers for a great post.
Sorry for probably missing something obvious, but what’s the key to getting the description to display for a term in the taxonomy? For a category the hard-coding is:
but what’s the equivalent for taxonomies? And for users of the Custom Taxonomies plugin, what’s the non-hard-coded way to get the descriptions you enter in the taxonomy edit panel to display?
OK, I found it in this other post of Justin’s on custom taxonomies: http://bit.ly/9ldLdc :
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>
<?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?>
Hello Justin,
I have added the following code provided by you in functions.php :
add_action( ‘init’, ‘create_my_taxonomies’, 0 );
function create_my_taxonomies() {
register_taxonomy( ‘people’, ‘post’, array( ‘hierarchical’ => false, ‘label’ => ‘People’, ‘query_var’ => true, ‘rewrite’ => true ) );
register_taxonomy( ‘places’, ‘post’, array( ‘hierarchical’ => false, ‘label’ => ‘Places’, ‘query_var’ => true, ‘rewrite’ => true ) );
register_taxonomy( ‘animals’, ‘post’, array( ‘hierarchical’ => false, ‘label’ => ‘Animals’, ‘query_var’ => true, ‘rewrite’ => true ) );
}
Then in my index.php file in the loop I added the folllowing code:
ID, ‘people’, ‘People: ‘, ‘, ‘, ” ); ?>
Nothing was shown on the front end though in back end I was able to add custom tags. Kindly help me !!!!. I am in urgent need.
Sorry I added
echo get_the_term_list( $post->ID, ‘people’, ‘People: ‘, ‘, ‘, ” );
in my index.php
Kindly help me .
I’m trying to use custom taxonomies, have set it up the same way you have. However i get the error :
Catchable fatal error: Object of class WP_Error could not be converted to string
Anyone have any idea how i can fix this ?
thanks
joshua
What i must do for show url like yoursite.com/people/will-smith ?
I add code ID, ‘people’, ‘People: ‘, ‘, ‘, ” ); ?> in my single.php, but when click on “will-smith” there is 404 error.
Hell to the Yeah! Thanks for sharing this…it seems to have been hidden for so long now. This is a total game changer for Wordpress as a CMS
great post. i’m just getting started in WP, and already loving it, so keep up the great tutorials.
I do have one question. I am setting up a music video site, where the videos will be the posts. And my custom taxonomies are:
genre
artist
(record) label
album
So for each post (song), I am filling in the genre, artist, label, and album (where appropriate) terms.
But it seems to me not an optimal data structure. For example, the genre should really be a “property” of the artist i.e. set up once for each artist, not set up for every song …. its just duplicating the information, when it should only be stored once.
So how would I go about doing that sort of thing, is it even possible in WP2.9? I can see lots of relationships in the information but no real idea how to represent it with the WP custom taxonomy structure / admin interface.
Any tips welcome.
This is really wonderful, but I have one question: I’ve registered taxonomies, they work really well, but for some reason the rewrite doesn’t work! So if i click on http://mysite.com/mytaxonomy/taxonomyterm (which is autogenerated by the cloud) it brings me to a 404. do you know why that may be?
The same problem is happening to me. Everything works just fine, but when I click a term in my taxonomy cloud, it gives me a 404 error. I have a taxonomy.php template in my theme folder.
Any help with this?
I’m having the exact same problem. Anyone find a solution for this?
Found the solution: resave the permalinks.
Justin, great post! I’m amazed! Thanks! I have been using tags all this time.
great tut, thanks! I’m trying to incorporate it with custom post types, it works quite good besides the url rewriting issue..
I can get to mysite.com/country/cityA or mysite.com/country/cityB (country is the custom taxonomy) but I can *not* get to mysite.com/country .. it gives a 404. I would like to list all of the cities for this taxonomy but anything I try (using taxonomy.php or taxonomy-country.php or resaving in the permalinks section) doesn’t work..
Any ideas on that? what would be the equivalent of archive.php that will catch and display it?
big thanks anyhow!
Great tutorial,
Thanks a lot!
I have a question, tough. This is quite cool for someone who needs additional taxonomies. However, I think that a similar approach can be used by simply using categories and child categories. This is pretty much what I need in my case.
since wordpress function to list categories allows you to add/subtract categories, or show only categories which are child of a given parent subcategory, I am pretty sure one could achieve the following example by only using categories. Imagine the following drop-down menus
CITY
-> New York
-> Chicago
-> Philadelphia
FLAT
-> 1 bedroom
-> 2 bedrooms
-> 3+ bedrooms
In this example, have two main categories (CITY and FLAT) and each one has 3 child categories. The idea would be to have two drop-downs for each category. I am sure this is possible.
However, the category widget for Wordpress is pretty bad (since it doesn’t allow me to pass custom php code for it, such as to remove a specific category), and to do this coding by hand would be a pain…
any ideas?
This is a great blog post – I just spent time reading the entire thing and comments. I am left with two questions though that you can hopefully help with. This is in regards to a project I am preparing to work on. I will be using Wordpress 3 (currently developing using Beta 2) along with the Custom Post Type UI Plugin.
1. Is there a way to have the same taxonomy appear on two different post types? I am going to be using custom meta boxes for each post type but also want them to share the same taxonomies. Make sense?
2. Is there any way to have the taxonomy boxes include predefined tags? Ex, have the user just click on the different options under Genre instead of typing them in. I am going to be having multiple authors and do no want any spelling mistakes that could cause problems in the future.
Thanks again.
1) I have the same question. So far I have not found a way for different Post/Content Types to share a Taxonomy, other than faking it, but I hope I’m wrong. Let’s assume:
post type #1 : Articles
post type #2 : Reports
(not really) shared taxonomy : Color
I have a taxonomy “color-articles” with Label “Color”, and another taxonomy “color-reports” also with Label “Color”, so they seem the same in the Admin. Each taxonomy can have Terms “red”, “green”, and “blue”. But they are not actually connected in the database, and the slugs for terms in color-reports become “red-2″. Not ideal.
2) If you register the taxonomy with ‘hierarchical’ => true, WP will automatically show the terms as checkboxes! (With a scrollbar if the list gets longer than about 10 items.) I learned this today, thanks to Michael Fields (http://wordpress.mfields.org/taxonomy/).
Answer to your Question 1: I think we actually can SHARE TAXONOMIES among different custom content types. When we register a Taxonomy, we specify a single content type. But when we register a Custom Content Type, we can specify various Taxonomies that it uses (http://codex.wordpress.org/Function_Reference/register_post_type ).
I had been using a plugin to create my custom content type (Custom Post Type UI), so I didn’t realize there are more things we can specify by doing it manually in functions.php.
Now my custom taxonomy “Color” appears under both of my content types (Articles, Reports). And the Count for each term includes both content types.
Thanks to Chris Coyier & Jeff Starr of Digging into WordPress (http://digwp.com/2010/05/guide-new-features-wordpress-3/) for pointing me in the right direction.
Greetings, I looked through the comments and don’t think this is a duplicate.
I’m upgrading an old site that uses a category based permalink structure, in the admin panel I did a custom structure of: /%category%/%postname%
I now have more a more meaningful taxonomy of country around which I want to structure my permalinks, for example: /%country%/%postname%
Any ideas how it’s done?
Great Article Justin. You have a great style of explaining hard to grasp concepts to the average , non technical wordpress user.
Two things. I notice that you promote the book Digging into WordPress. Why don’t you write a book yourself on WordPress 3.0? I would be your first customer. Most of the books out there are not even close to your ability to explain how to use the power of WordPress. For instance I did not know that custom taxonomies were available since WP 2.8.
Secondly you asked for scenarios. My use example is of a mortgage comparison site.
I have an old static site on mortgages that I want to rebuild in WP 3.0. [I have several wordpress blogs]. I want to make it useful for people to self-compare mortgages available, and for them to be able to preview what loans are availble for their situation.
How would I best use custom posts and taxonomies on this site? [Why did you elect to go for non hierarchal taxonomies.]
Most people only focus on interest rates.
Loans however could be classified by, Funder, loan size, down payment, lender, lender type, distribution channel/s, loan type, client type/ employment stability, income and job type/ partners/ downpayment, mortgage insurance [variable on deposit amount] loan purpose, loan costs, Property security, loan size, Interest fixed or variable or combo/ revolving credit line, Repayment options, Loan style, Loan options, Interest rates, Introductory discount offers, Loan terms, Loan conditions, Early repayment options, application fees, establishment fees, ongoing fees and charges, deferred fees, early repayment penalties, default fees and interest rates, default processes, Loan documention type, Credit rating/history/ scores. etc.
E.g. Client type could be first home buyer, self employed, with less than two years income/tax statements, with minor credit defaults. In Australia he would be paying a higher interest rate than a professional, such as an employed lawyer on $150,000 with clear credit, and be precluded from applying with many lender types. Incomes,dependents and financial commitments can also affect the
Each one of these can have a multiple choices, and or be dependent on other areas.
Any suggestions would be appreciated.
@Greg – When you register your taxonomies you give them a ‘rewrite’ parameter. That will be your permalink structure. If you default it to true, it will take the form of the name of the taxonomy.
This is so amazing. I’m trying to make ‘custom segmentation’ for menus in particular sections of the site (like ‘corporate solutions’ / ‘SMB’s’ / ‘DIY’ers.
I think taxonomies just opened up my eyes to the ‘holy crap’ level.
Hi ,
Its great tutorial to create custom-taxonomies, I want to customize design of
wp_tag_colud('taxnomy'=>'something');How t0 achieve this?
get_tag_link(); =>doesn’t gives links to the custom-taxnomiesWhy does it show that there is no such a thing, when I point to http://sportowewadowice.pl/taxonomy_name/taxonomy_object/ ?
Justin, I’m just searching around for a way of using
query_poststo gets all posts but exclude those with certain custom taxonomy values – likecategory__not_in. There doesn’t seem to be be anything definitive out there – can you confirm this? A bit disappointing that WP 3 brought in custom taxonomy support without full querying support…Nice. Thanks.
Maybe you can help? Is there a way to get all values across all taxonomies for a given post? We wanted to break up the tags into groups to make “queries” easier. But we’d also like to just list them with the posts like normal tag. Like the_tags().
I know we can do it taxonomy by taxonomy but then they would not be in alphabetical order. Maybe there’s a way to get the taxonomy values into an array? I realize that might sound counter intuitive to the use of taxonomies but it does make sense on this end. I’ll spare you the details
Nice article, very useful. Am using these now in conjunction with custom post types, and also have taxonomies that are not displayed to users. Just wondering if there is a function you know of for adding a term to a taxonomy, say through a line in functions.php?
Thanks.
Jonathon – great article
I am using this bit of code in a php widget:
All works fine and the tags show up in my sidebar… the only problem is that when i click on a tag to filter them. I am redirected to a not found page.
Note – this is for a custom post type.
Im a bit stuck here, so any help would be great.
Thanks!
just realized i wrote Jonathon instead of Justin… sorry about that…
I have a problem with displaying related post by custom taxonomy tags, using shortcode…
I post it on wp forum, here:
http://wordpress.org/support/topic/related-posts-by-custom-taxonomy?replies=12#post-1686951
Anyone can help!?
Thanks
That’s great. Do you know, how to set up special order for the terms of custom taxonomy? Thank you!
Hello, thanks a lot for the article! Really helpful – wish I found it earlier.
I’ve got a question: I have a ‘Portfolio’ custom post type with the following registered taxonomies “web”, “print”, “logo”. On my Portfolio page I wanted to group portfolios by thier taxonomies. I’m using get_posts(‘post_type=portfolio&nopaging=true’) to get all the portfolios… but I can’t figure out how I would go on grouping them by their taxonomy.
I would appreciate any tips!
Thanks
Great job Justin and thanks for this article! Helped me a lot to understand this powerful feature.
Is it possible to create a custom taxonomy and allow the user to select only one single term for that taxonomy?
I’m using custom post types (register_post_type()) and each custom post type has own custom taxonomies, and I want some of them to allow only one term to be selected. Let’s say a custom post of type “desktoppc” will have a custom taxonomy “cpu” and the user should be able to select only one cpu.
My idea is to use custom taxonomies as some kind of dictionaries and maybe then filling a custom-field dropdown (select/option) with all values/terms of this custom taxonomy…
But I’m not sure if it’s not reinventing the wheel.
Peace
hi guys
iam using custom taxonomies in my site,so i did have seperate templates for displaying them.
i have created a taxonomy called people and a term called star and also respective template to star (taxonomy-people-star.php) every thing works fine http://sportsstatus.in/dev/people/star/ .
but when i query some other taxonomy like http://sportsstatus.in/dev/people/star/?sports=tennis to it the template structure changes to the archive format. how to over this.
i want the original template structure assigned for star(taxonomy-people-star.php) to work.
Please help!
After I added that first piece of code in funtions.php to create a custom taxonomy, the admin panel went completely blank!
I was able to go back one step in browser history to remove that bit of code. But updating the file doesn’t help, now I’m terrified that I’ve lost everything!!
Thanks for this tuts.
I know if i was late, but this is very useful for beginner like me
I’m trying to figure out how to change “Add new tag” to “Add new people”… Any help would be greatly appreciated.
I am glad I found this article, I was starting to give up on my idea
Worked with taxonomies before (series-plugin) but never made one myself;
Quick question tho: If I go to Posts => my-custom-taxonomy in the dashboard I get this error: “Cheatin’ uh?”
I think it’s a database issue, but what did I do wrong? (testing on wp 3.1.2.)
I know this is a couple years old, but it’s still helpful. Thanks.
very nice tutorial thank you very much
Justin,
I am using your “How to list a taxonomy’s terms for each post” technique
However I would like to be able to remove a specific taxonomy from the list.
Specifically, several posts in my custom post type are marked with ‘current’ as a taxonomy.
When displaying the taxonomy terms for each post, if it is marked as current I do not want current to be displayed in the list.
I’m thinking of trying to do a string replacement, but I’ve never done that before so I am researching that now.
Does anyone know how to accomplish this?
I was able to get a string replacement to work. For anyone who is interested this is what I ended up with: