123 responses to “Using custom taxonomies to create a movie database”

  1. Ozh

    This is honestly one of the most awesomest posts I’ve read about this tricky feature that is taxonomies, since they were introduced in WP. Very practical, very simple. Great read!

  2. rgregory

    I REALLY want to understand taxonomies, but just can’t. Why wouldn’t you use tags?

    I’m sure this happened when tags came out, many people must have thought, “why not use categories?”

  3. Remkus

    Couldn’t agree with Ozh anymore. Makes me wonder if custom taxonomies are what I need to create a family tree (design) in WordPress. Thanks!

  4. Iva

    This is going to help me a lot with gigography and lyrics on a website I run. I hope it does not use up too many queries. Thank you. :)

  5. Andrea_R

    This is pretty flippin’ sweet..

    OOOO! Do the same, but make it authors and books. *drools*

  6. amalik

    great post, as usual !

  7. Kim Woodbridge

    This is wonderful! It’s one thing to understand taxonomies but it is SO awesome to see them put to a practical use.

  8. Iva

    Justin: Thank you. Now I’m intrigued, what would useful things be? The site itself is a crossover between a fansite (I find the term fansite offensive, because fansites are usually designed by people who don’t know coding, design in obsolete ways and steal everything they possibly could) and a news blog; and it never utilised categories and tags for anything other than news, everything else resides on pages; but I often end up interlinking those pages the old-fashioned way.

    I’m basically waiting for WP 2.8 to start developing the site’s next version (ever since I’ve seen the original tutorial on taxonomies) because of taxonomies AND clearning my documents’ head from unnecessary things some plugins appear to be generating and I’m always open to beta-testing interesting things once it’s happened. The lack of custom custonomies was the reason I never opened the gigography section to public and the reason two other sections are half-a$%ed.

    I guess I’ll jump to the forum.

  9. Iva

    Custom taxonomies not “custonomies”.

  10. Thomas Clausen

    Justin this is a fantastic post. I can see a bunch of uses of this great feature. And I must agree with Andrea_R that this would be cool with a book-site. But why stop there, any kind of shop/review site could have great use of this. But what about a food- or estate-site? If only one could choose to cross-reference different taxonomies.

    I have asparagus and potatoes in the fridge, what can I make? Or
    I would love a office in Copenhagen for about X $

    Anyway, love the tutorial, can’t wait for WordPress 2.8…

  11. amy gail

    Justin, this is exactly what I’ve been trying to figure out for the past couple of days.
    Thanks so much!
    This will be extremely useful for a site I’m building for a large band with a large discography.

  12. Jason

    YOU are a Ninja. I’ve just started using taxonomies for a real-estate theme/plugin that describe properties in a separate sidetable (not posts or pages) — love the flexibility of the WP taxonomy API!

  13. Matt Wiebe

    Justin, thanks for this. Ever since taxonomies were introduced in 2.3, I’ve been waiting for someone to talk about them technically and give an excellent example of how they might be used in a real-world scenario.

    Also of interest might be the Custom Taxonomies plugin, which lets you create/manage taxonomies without writing code.

  14. Matt Wiebe

    Ahh, now I see that 2.8 will be bringing a lot of the advantages of that plugin into the core, which is great.

  15. The Frosty @WPCult

    Such a great tutorial, help me understand taxonomies more!

  16. Cristi

    Ok… just one question… is there somethings about Wordpress that you DON’T know? :)

    Thank you for explaining this in such detail. I think I have just the project to implement this technique.

  17. Dumitru Brînzan

    This will surely prove to be a great tool in creating niche websites.

    No more boring category/tag structures… This is really awesome!

  18. Daily Digest for June 5th | Digital Gilbert

    [...] Using custom taxonomies to create a movie database [...]

  19. Vix

    Brilliant tutorial! Count me in as one of those who understands the term “taxonomy” but didn’t have a clue as to how to practically use it. This is exactly what I need for my collections database!

  20. Sarah

    I’m so glad to have found this great tutorial!!
    I do have a question Justin.
    You talked about creating a taxonomy.php so tag.php won’t work with the custom taxonomies?

  21. Today in WordPress world - 05/06 | Links | WereWP

    [...] Using custom taxonomies to create a movie database (tags: WordPress 2.8 tutorial taxonomies) [...]

  22. Chris

    Thanks for the tutorial! I created a custom taxonomy of ‘technologies’ and a term of ‘php’ but when I enter a url of http://www.mysite.com/?technologies=php I get the wordpress 404 error (I also get it if I try http://www.mysite.com/technologies/php). I copied my ‘archive.php’ file, renamed it ‘taxonomy.php’ and included “‘query_var’ => true” when registering the taxonomy… Any ideas?

  23. John Myrstad

    Great article Justin.

    O`Reilly should really call you ;)

  24. Sarah

    Right, well that makes sense. Can’t wait to try it out in my next project

  25. EmmaBShireen

    This would be perfect for organizing my anime&manga blog. There are so many genres that one series can fall into so it gets hard to figure out how to tag it. This would make things a lot easier!

  26. Robert

    Justin, thanks for the detailed posts on taxonomies. Wonderful to have it all digested like this.

    Just recently I’ve come across the Pod plugin that provides a framework for creating custom content types and relationships between them.

    I know that this is different to custom taxonomies. Seeing that you have aquainted yourself with WP 2.8 already, my question is (if you are familiar with the concept of the Pod plugin) whether WordPress 2.8 has any new features that would bring something like custom content types closer to the ‘core’ just like the custom taxonomies.

    One of the most important things with content is the searcheability of said content so being able to create custom content types natively would mean the ability to use the native search functionality.

    (Kudos to the guys that created the Pod plugin though, it seriously redefines what you can do with Wordpress.)

  27. iamcracks

    */ just wanting to follow the comments */

  28. Paul

    Great post Justin. This is very valuable information and perfectly timed. Cheers.

    Can you advise a plugin or other, that would allow for advanced searching of custom taxonomies? For example, from your example above, produce a result of all the movies starring Tom Hanks and Brad Pitt that were directed by Ron Howard.

  29. Dave

    Very neat explanation, I wish I could find one earlier :( By the way, but what would you do if you want an actor or a director to have it’s own page, with more then just a photo and rich text description? Let’s say you want it to be as rich as your ordinary page, with user comments on it maybe, etc? Hmm… that’s an idea by the way, to add rich text editor to taxonomy description textarea!.. But what should one do with comments? Any straightforward way to bind them on taxonomy template?

    These plugins implement custom taxonomies in more intuitive way:
    http://yoast.com/wordpress/simple-taxonomies/
    http://wordpress.org/extend/plugins/custom-taxonomies/

  30. Niraj

    Brilliant explanation and marvelous patience and steadfast diligence in answering the comments! Thank you! I’ll be exploring your theme framework.

  31. Dani

    Great post Justin!

    Your ideas and tutorials fit perfectly with what I’m trying to do at my site, but it expands the posibilities.

    Until now, I was creating a animation movies database similar to the one you’ve created. I made it based on pages and custom fields. You can see it here: http://www.protoones.com/film

    Now, I will replace custom fields with taxonomies for sure!!!

    Still, I have one question: I have created child pages with videos (trailers, clips, featurettes, …) for each movie. How would you create this “child pages” in your movie database?

    I’m not sure that a video should be a taxonomy. An actor or a director may appear in differente moviesm then we use taxonomies. But a video only belongs to one movie. Right? So, what we should use for videos?

    What do you think?

    Thanks!

  32. Ipstenu

    Argh. I have a ton of wordpress ‘tags’ in use with the format :, essentially. This would be a perfect way to fix those, but. There’s no easy way to move tags between taxonomies. Bleah.

    SQL time!

  33. Paul

    Hey, I have a custom taxonomy called people, but the code that you wrote to get the proper name of the taxonomy term doesn’t show up the title on my archive page (taxonomy.php) for people. Any ideas?

  34. Mike Schinkel

    “It’s beginning to look a lot like Drupal
    Links make vistors engauge
    But the prettiest sight to see is the taxonomy that will be
    On your own front page.”

    But seriously this seems like 1/2 of the solution the other half being custom post types. That said, where did you add your ” image and short description of the (Tom Hanks)?” Seems like an “Actor” custom post type would be the perfect solution, no?

  35. Larry

    Is there a way to sort theses in alphabetical order by taxonomy?

    I am looking for my post page to be in alpabettical order by a tag and it seems impossible.

    Will this work? and if so how. Lastly, What kind of stress does this put on the database have so many terms to process, if any at all?

    Thanks and this looks awesome.

  36. Dani

    Justin,

    I will take a look at the attachments solutions you mention. Even though I don’t think it will work for my website because most of the videos are not uploaded, they’re just embeded from YouTube, Vimeo, …

    On the other hand, I’ve been looking at your database and I have few more questions.

    What kind of object are your movies? Posts? Pages?

    If they are pages, I imagine you’ve created your own custom panels to add taxonomies to pages… Then, can you write another tutorial on how to do it? Or, even better, can you create a plugin “Taxonomy for ages”? ;)

    Lastly, for me, movies should be a taxonomy because if I write a post in the blog I should be able to tag movies, directors and studios in the same way using taxonomies. But if I made movies as taxonomies, I can not add actors and directors to movies, right?

    So, in your popcritics web, how will you link posts in the blog section with movies in the database?

    Thanks a lot!

  37. Garrison

    Justin, I just found your post via WP Topics and I’m interested in exploring this technique for my site, and indeed some future projects.

    A little while ago I was looking at how tags could be grouped and this seems to be the solution but I’m a little unclear as to whether using this techniques means negates the use of categories?

    For example, I use categories exclusively for geographic information e.g. Continent > Country

    I then use tags to describe the posts in terms of style of tents (e.g. yurts, tipis); activities (e.g. fishing, kayaking etc); setting (e.g. coastal, mountains, lakes etc) and so on…

    The problem is these are all lumped together whereas it would be better if they were grouped.

    If I use custom taxonomies, as you’ve described in your post, will I still be able to use categories for the geographical aspects?

    Using categories in this way on my site offers me the ability to easily manage them in the admin plus other advantages, also there’s the hierarchical aspect as later I’ll want to drill down to regions within countries as the site grows.

    @Dani asked ‘What kind of object are your movies? Posts? Pages?’

    I too am interested to know this but I am hoping they are categories ;-)

  38. Paul

    Hey Justin! Thanks a lot, it worked like a charm. Great post!

  39. Larrry Scott

    Refining my question.

    Is there a way to sort by a second term.

    i.e. I have am able to get a list of “Actor Types” – Union, Non Union.
    So i get a list of all the “Union” Actors(term).
    Can I sort that list by a second term , Say “Last Name” in alphabetical order?

    How would you do something like this? Is it Possible?

    Thanks again,

  40. Garrison

    Thank you Justin, much appreciated.

    Apart from your PopCritics’ treatment of custom taxonomies, do you know of any other sites out there that are implementing this feature?

    I can see this becoming more popular over time and at some point it would be neat to be able to filter and mix by taxonomies. A nice idea would be to create a search tags function much like on Delicious where you can select and unselect a selection of tags to sort results by.

    I find most blogs badly structured and see people use categories for ‘featured’ content, always a bad idea.

  41. Praz

    can you share the css that you’ve applied with the movie database? is it possible to get the whole template of the movie database?

  42. Mike Schinkel

    @Justin: Thanks for the reply however this is what I read and it’s still unclear what you did: “Once that was done, I found Tom Hanks under my Actors taxonomy in my WordPress admin (a sub-menu of Posts). I then added an image and short description of the actor. This shows up at the top of the Tom Hanks archive:”

    To what did you add the image and short description?

  43. Garrison

    Thanks again, Justin.

    Your Theme Hybrid Showcase is a good example for me as it mixes various taxonomies such as categories (theme), custom taxonomy (color), tags (tags)

    One thing I noticed is the URLs are not closed with a trailing slash. Is there a reason for that? I’ve been told it’s better to close URLs.

    Also, if I hack back to: http://themehybrid.com/showcase/color/ I get a 404, but I was hoping to see a page with a list of colours. Note: this is the same problem if I hack back to: http://themehybrid.com/showcase/tags/

    The breadcrumbs don’t mimic the URL, i.e. the label ‘color’ doesn’t precede the color.

    I see on PopCritics that you have set up pages to handle the tag clouds for each custom taxonomy, e.g. http://popcritics.com/movies/genres/

    But again, the breadcrumb system doesn’t contain a link to these custom taxonomy pages.

    Can your breadcrumb system, or any other system, be correctly set up to contain links to these custom taxonomy pages?

  44. thegirlinthecafe

    What a fantastic example! And the possibilities of this are endless. Thanks for explaining it in a simple way!

  45. Adriano Estevam

    Hi Justin,
    Again, a nice article.
    Is that a way to add extra fields to taxonomies besides name, slug and description,? Like, i would like to add a field like “image” or “ISBN” . What would be a good way to do that?

    All the best,

    Adriano

  46. Praz

    Hi Justin,
    I was just trying my hands with your hybrid theme. How can I remove ‘by author_name and date’ from the excerpt(home.php) and single.php?

  47. clau

    How do you apply css and html to the taxonomies.

    Like to show the genres in bold and to make it in two lines (genres, new line, and all the tags)?

  48. Robert

    @Adriano Estevam

    You can check out the Pod plugin I mentioned in my earlier comment here that provides a framework for creating custom content types and relationships between them. With that you will be able to create various custom content types with relationships and link them up similar to the custom taxonomies here.

  49. (Anti) Social-Lists 6/14/09 | (Anti) Social Development

    [...] Using Custom Taxonomies to Create a Movie Database – Custom Taxonomies are going to be used mostly by developers in WordPress 2.8. I understood them theoretically but was really please to see a practical use of them. I would like to try this with a video game database. [...]

  50. George Serradinho

    This is just awesome:)

    You have just explained it in simple terms and for anyone to understand. You have given a greta idea for a project of mine.

  51. Dani

    Hi Justin,

    After you answered me that, in your database, movies are posts I thought it was not what fit my needs because I want to “tag” posts on the blog with the movies they talk about.

    Also, you build the database in a different site and you can not easily link blog posts and movies.

    So, for me, movies should be taxonomies. But, then, I can not “tag” movies with genre, actors, … right?

    To solve this issue I’ve found a solution: I create a movie as a post and as a term at the same time. Both have the same slug/name. Then I modify the taxonomy template page to include content form the post and the term.

    The code to include the post in the taxonomy looks like:

    What do you think? Any ideas to improve this solution?

    Thanks!

  52. ilovewp

    Hi – To use your movie database example, I’d like visitors to be able to view the Tom Hanks page, even if Tom Hanks is not in any movies. So it would show the term description as usual, but then a message saying ‘No movies for this actor’.

    I can successfully generate a list of all actors (including ones who are not in any movies yet) using the function get_terms() with ‘hide_empty’ set to zero, but I get a 404 error if I try to visit a term page that has not been associated with any posts (an actor in no movies).

    Do you know if there is any way round this?

  53. Mike Schinkel

    @dani: Your approach sounds like a great way to combine posts and tags (I once did something similar in Drupal; not sure why I didn’t think of it for WP.)

    BTW, your code wasn’t included in your comment on the web page but I did get it in my email notification of your comment. I’ll try adding it for you below but in case it doesn’t work here’s hoping that @Justin will fix it:

  54. WordPress 2.8 is uit (+Resources) : WordPress Dimensie

    [...] Using Custom Taxonomies to Create a Movie Database [...]

  55. clau

    I was able to set up everything in my blog to use taxonomies, Im also doing a kind of movie database, they really help a lot.
    But do you think they can slow down my site? because im feeling like they do.

  56. Narc

    How did you get the breadcrumb functionality to work with the custom taxonomies?

    Also, with respect to creating a separate taxonomy.php file, how do you get a taxonomy to use this file by default?

  57. Adria Richards, ButYoureAGirl.com

    I went to WordCamp Chicago this month and Matt Mullenweg addressed the audience about what was going on with Wordpress. I was surprised he spent time talking “techie” and was intrigued by this taxonomy thing. He also told jokes and told the story of how Wordpress got started.

    I’m happy to say, with Justin’s awesome Wordpress plugin, Series, I created my first set!

    http://freshworkshops.com/series/google-apps/

  58. ilovewp

    thanks for your reply – it would be great if that gets fixed in 2.8.1

    just out of interest, what do you have your permalinks set to? i see there is no date, category, etc, in the url before the movie name, so it’s very clean.

  59. Francois

    Hey Justin,

    If a taxonomy term does not have any content yet, it seems that is going to another page, no the taxonomy.php. Is it going to the 404 not found page ??

    Thanks.
    François

  60. Idee für den Einsatz von Custom Taxonomies « Black-Forever

    [...] auch gebrauchen. Justin Tadlock hat in seinen Tutorials – insbesondere mit dem Beispiel der Film-Datenbank gezeigt, was man durch die Custom Taxonomies in WordPress recht schnell realisieren kann. Für mich [...]

  61. Brian

    Justin; great posts … I’ve been reading through and have had good luck using taxonomies.

    Question though; can you either explain or show the code you used for the movie database, that allows you to pull the image from your posts (movie posters) and display all of them on to one page? Your explanation of how to add “Tom Hanks” information in the header area was alright, but there was no information about how to get all the images from separate posts into that archive/page.

  62. Critical WordPress Theme

    [...] month, I wrote a tutorial on custom taxonomies and how I used them to create a movie database. As an example, I created a custom child theme for [...]

  63. Ditutu

    Great post , it had really hepled me . Good job !

  64. topdownjimmy

    Because this post seems to be such an important resource for people making custom taxonomies, I thought I’d note here that I learned the filename format for template files for individual taxonomies (rather than a catch-all taxonomy.php template that affects director pages, actor pages, genre pages, etc.

    It’s taxonomy-slug.php; so, to use this post as an example, if you wanted your director template to be different from your other custom taxonomy templates, you’d just create a file called taxonomy-directors.php.

    Thanks Justin for this great post — of all the WordPress hacks I’ve learned, this is maybe the easiest to implement and also the most useful. It really stretches the boundaries of what WP is capable of.

  65. The Making of a Monsta … WordPress Theme | Jeremy Adam Davis

    [...] I had to learn how to make custom taxonomies. Taxonomies are things like Categories and Tags in WordPress.  My theme has a custom taxonomy for my portfolio tags so that when I tag a portfolio item with ‘blog’ it does not get intermingled with my posts that are also tagged with ‘blog’. Here’s a few good posts on custom taxonomies: Custom Taxonomies in WordPress 2.8 Using Custom Taxonomies [...]

  66. Brian

    Justin, tell me – how were you able to add an image inside of your tag description? The above example is of Tom Hanks; his picture followed by “Tom Hanks is quite possibly…”

    I’m left kind of scratching my head as to how you accomplished that.

  67. ConradH

    Another great tutorial… Thanks Justin!

    I’m using custom taxonomies for a site that has both a blog and a portfolio. There will be one category for text posts and one category for posts containing photos. I’d like to use custom taxonomies to classify the photo posts with additional data, and may occasionally have blog posts related to those classifications that would get tagged using the custom taxonomies as well. What I’m not sure of is how to do two things:

    1. Query posts that are under both one category and one taxonomy term
    2. Query posts that are under multiple taxonomy terms

    Any help would be greatly appreciated as I haven’t seen any info on this yet. Thanks again.

  68. New And Comprehensive Wordpress 2.8 Tutorial and Hack Toolbox | Graphic and Web Design Blog - Inspiration, Resources and Tools

    [...] 17.Using custom taxonomies to create a movie database [...]

  69. Jamie

    I’m wondering, is it possible to intersect tags. For example if I am looking for movies that star Tom Hanks, AND are also action movies? Or Martin Scorsese films that are also Academy Award nominees (assuming the award nomination existed as a tag)?

    Being able to narrow on multiple tags simultaneously seems like a bigger advantage than simply grouping tags into sets (“taxonomies”). To select a tag and then generate a tag cloud for all items (and only those items) with that tag would really be cool.

    It’s unclear if that is possible, and if it is, whether this is part of it.

  70. Garrison

    @Jamie: I think that’s a great idea and one I’d like to see also. On one of my sites I will use categories for countries and custom taxonomies for: type of accommodation, style of accommodation, suitable for, activities etc.

    So, it would be great if my users, when viewing listings in Spain could drill down using the various taxononies e.g. villa, boutique, couples, swimming (as an example based on the array above)

    Sort of like filtering as used on Delicious.com, with a similar interface i.e. you enter the tags and search and to remove them click the [x]

  71. Ashton

    Wow, this is such a cool post. Thanks! Can I ask how did you get the info to make the DB. I run a Dance Studio and this post opened my mind up to creating a “DB” on Dance movies, Songs and Quotes which my viewers could use and love. I’m often referring them to various movies depicting a visual of dance…this could really be right up my alley. Do you think you could help?
    ~Ashton

  72. vvvvv

    hey justin,

    you mind dropping a slight of knowledge bombing, on how you were able to query all posts that were under the taxonomy of “movie” via http://popcritics.com/movies/ ? big thanks!

  73. ConradH

    Thanks for the response Justin… I can dig in and try to write some SQL to hit the wordpress database. This may be a dumb question from newbie at advanced wordpress coding but when you write a custom query like that what is the best way to display results and have useful URLs, not just for the initial result set but the links from each result to (in this case) a page displaying content with multiple specified tags? Curious for some direction and ideas. Thanks!

  74. vvvvv

    hey justin thanks for the response.
    is it possible than that you’d be able to show us how to write a query that show’s a specific taxonomy and all its terms, including having the proper permalink structure?
    i made a request over in WP support forums on a thread you commented, but it seems like alot more light is shed here. would be really appreciated.

    for example, if you had a taxonomy called WORK, and you had terms such Design, Logotype, Artwork, Illustration, etc. It would be ideal I’d think to be able to show all the terms filed inside the taxonomy of WORK in many cases. Thanks again.

  75. Bethany Trinoble

    Cracking post, I can see so many ways to implement this on my sites. Many thanks for the instructions and detail.

  76. Ray

    Great overview on how to use custom taxonomies in a real-world setting.

    My only issue is with duplicate content.

    Let’s use the Tom Hanks example. If I “tag” Tom Hanks with the taxnomies of “Actor” and “Producer”, wouldn’t that be almost considered duplicate content?

    eg. hxxp://example.com/actors/tom-hanks
    hxxp://example.com/producers/tom-hanks

    Wouldn’t it be better to have a “Tom Hanks” page/post (eg, hxxp://example.com/tom-hanks) where you use a custom page template to output the taxonomies he is associated with? Then use the canonical header tag to direct all the different “Tom Hanks” taxonomy pages to that page?

    I know this might be considered redundant considering the basic usage of taxonomies, but just a thought I had.

  77. Michael Oeser

    I think I did anything that´s mentioned in this tutorial but for some reason I get an 404 error when clicking on a taxonomies term.

    A bit more in detail: I display the different taxonomies below the single-post (such as tags). That works fine. When I click on a term I only see my 404 page. It seems as if the template “taxonomy.php” (a copy of my archive.php without the conditional stuff) can not be detected or is not working at all.

    Is there any known issue in WP 2.8.3? Or what else could be a reason for this? Any ideas?

  78. benz

    To solve the 404 error issue, the trick is to call $wp_rewrite->flush_rules(); after registering the new taxonomies.

    Without doing this the rewrite rules won’t be updated, this means that if you are using pretty permalinks wordpress will never figure out that you are asking for a new taxonomy and will never work out what template to load – it always 404s.

    The problem is that you can’t just call the flush_rules in your functions.php after you register the taxonomy, it should only be called _once_ after you first register it, and again only after you unregister it.

    If you write a plugin its ok, as you can add this to the install and uninstall routine, but if you are taking advantage of 2.8’s improved taxonomy handling to do this in functions.php its not obvious how to include this sensibly – for testing I’ve just called it once, then commented it out and that works, but my theme is no longer portable.

    Justin – how have you handled this issue?

  79. benz

    Quick Correction – calling flush_rules in functions.php doesn’t work (you can still use it in a plugin), instead you can open the Permalink Settings page in admin, this triggers a flush_rules event.

    Having done this my taxonomy templates now work as expected for urls like mydomain.com/actor/tomhanks ie you can now use taxonomy-actor-tomhanks.php, taxonomy-actor.php and taxonomy.php.

    I still haven’t found a way to elegantly handle this in a theme however.

  80. vvvvv

    hey justin, thanks for the reply.
    sorry, i’ve miswrote what i wanted to say.
    (i think what im requesting for has been brought up in the WP support forums before)

    it’s not that i want to show the actual terms… not in this case at least.
    what i’m aiming for is to show the posts that part of a specific taxonomy…or even… a specific term of that taxonomy. so i’m wondering, how would you go about building a query to rack together i.e any posts filed under the taxonomy of “WORK.”

    thanks again.

  81. ConradH

    vvvvv – Here is a query for getting all posts in a specific taxonomy term (in this case the taxonomy is called “locations” and the term I’m getting posts under is in a variable called $location_name):


    query( array( 'locations' => $location_name, 'showposts' => 5 ) );
    ?>

    I don’t know of a way to display all posts using any term in the “locations” taxonomy other than using custom SQL:


    SELECT *
    FROM $wpdb->posts
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->posts.post_type = 'post'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->term_taxonomy.taxonomy = 'locations'
    ORDER BY $wpdb->posts.post_date DESC

    You’d then loop through the results and display. More info here: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    Justin – I didn’t explain myself very well. Let’s say I have a query that returns all posts that are in one category and have a specified taxonomy term (or custom SQL or anything else outside the scope of typical archive/category/taxonomy pages). Right now, I would make a custom page template to contain that query and then create a WP page and give it some appropriate name and select the template. Page displays at mysite.com/page_name. Is that the best way to handle that situation? What if the query is ad-hoc based on some variables and it doesn’t make sense to use one specifically named WP page to display results?

    I just started reading the Custom Queries page in the Codex and may have answered my own question: http://codex.wordpress.org/Custom_Queries

  82. Michael Oeser

    Thanks Justin, updating the permalinkstructure solved the issue.

  83. clau

    Hi. Mmmm so im doing a database like the movies you maked. Do you think there could be a way to make something like an advance search, so you could check like the genres you want and it will show, that were maked with taxonomies.
    Any plugin or idea on how to do it? =)

  84. Fuji

    Great post!

    When exporting the WP posts it doesnt seem to export the taxonomies.
    Meaning it would also be difficult to import them.

    I want to import my csv file (csv 2 post) and include the taxonmies.
    Does anyone have an idea on how to do so?

    Thx

  85. sinschild

    I can see this being very useful for some of my ongoing projects. Do you think it is possible to sort the resulting tags by number of clicks? Maybe increment them in the DB every time and use that to roll them up higher in the order they are shown? This is just one more step towards being able to use WP as a full blown content mgt system for all my needs. Thank you!

  86. danwe

    interesting stuff, im definitely gonna be using this on my site!

  87. Thomas Scholz

    Justin, may I ask you to put your tip from http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database#comment-130638 (re-save the permalink settings) into the main text of your fantastic tutorial?

    Thanks.

  88. Maor

    Justin,
    Great work adn explanations.
    I’ve added new taxomony for my site and I want to have a sort of a glossary and a page template to show it. How can I add such a thing with the taxonomy?

  89. Cursors

    I was scouring the web for this. This is the first time on your site and I just spent like 8 minutes browsing and reading comments. You’re doing an awesome job it seems. I’m trying to get familar with wordpress also for CMS I want to use on my site.

    I didn’t know it was called Taxonomies…good to know =D

  90. Andy

    I’d just implemented my own custom taxonomy, but couldn’t get the pretty permalinks working – but sorted now thanks to Justin and benz.

  91. A Basic Explanation of WordPress Taxonomies | vsellis.com

    [...] Using Custom Taxonomies to Create a Movie Database [...]

  92. Scott

    I double the tip on putting the settings -> permalinks trick in the main tutorial. I almost missed this, and I’d be lost without it.

  93. Scott

    Hey Justin could you please explain this line in greater detail?

    register_taxonomy( 'actor', 'post', array( 'hierarchical' => false, 'label' => __('Actors', 'series'), 'query_var' => 'actor', 'rewrite' => array( 'slug' => 'actors' ) ) );

    You did some new stuff with the label and rewrite that I’m not totally understanding yet.

  94. images custom fields - WordPress Tavern Forum

    [...] a post written by Justin Tadlock which may help you quite a bit using custom taxonomies. http://justintadlock.com/archives/20…movie-database WPTavern Twitter Account | Personal Blog | WordPress Weekly [...]

  95. typoglyphic.com » 10 Tutorials to Take Your WordPress Development Skills to the Next Level – designm.ag

    [...] 1. Using Custom Taxonomies to Create a Movie Database [...]

  96. 10 Tutorials to Take Your WordPress Development Skills to the Next Level | Web Design Byte

    [...] 1. Using Custom Taxonomies to Create a Movie Database [...]

  97. safia

    Do you have any ideas about how to add meta boxes to the term description page? Is it possible to use add_meta_box or should use a filter?

  98. 10 Tutorials for WordPress Development Skills | Gazan

    [...] 1. Using Custom Taxonomies to Create a Movie Database [...]

  99. Jason Kadlec

    Someone on this thread was asking about making custom templates for taxonomies. Taxonomy.php will get you started, but what about when someone clicks on the permalink of a post using a custom taxonomy? Assuming you want to preserve some context, like the side bar of posts using custom taxonomies.

    If you are in that position, this may help — I needed to create a custom single.php so that if a post is within a custom taxonomy it would show a different layout than a regular single post.

    This solves it for me:

    I put this code into single.php (clearing all other code out) then I created single-teaching.php and /single-default.php:

    $post = $wp_query->post;
    if ( is_taxonomy('Album') )
    	include(TEMPLATEPATH . '/single-teaching.php');
    else
    	include(TEMPLATEPATH . '/single-default.php');

    Basically, if the post has any tag from my “Album” custom taxonomy – then display that post using the file single-teaching.php otherwise if it does not have a tag from the ‘Album’ taxonomy applied, then display the post using single-default.php

    In my case, I have posts that are blog posts, and posts that are “lessons.” The lessons are chunked up into major and minor categories and finally down into individual posts that either sell a pack of lessons. The packs of lessons needed a link to enable drilling down to see a list starting with the offer for the pack of lessons, followed by each individual lesson.

    I’m using categories to create navigation through the lessons and for reasons too long to explain here, I found that creating this custom taxonomy called “Album” did the trick so that I could first display a feed of all the Albums belonging to a major or minor category, then provide that “View all albums in this series” link courtesy of the custom taxonomy “Album.” Clicking on the link shows each post having the same Album tag.

    This could not be done with categories+sub-categories or at least not as I could see, because Wordpress always wants to list all the categories a post belongs to. Sure, you can limit that by saying just display a category ID, but this needs to scale such that I can’t go hard coding category numbers in all the time.

    I didn’t want to use tags, because the lessons already have tags that describe the content of the lesson.

    Then, I discovered this additional bonus! Custom Single.php if my post is an “Album” ! How good are custom tags?!

    And another additional bonus I just realized while typing this. I can have lessons show up as parts of more than one album — allowing my client down the road to mix and match existing content just by assigning the same Album tag to any group of lessons.

    Thanks Justin for getting me started down this road!

  100. Michael Patterson

    Hey Jason,

    What web site did you implement this on?

  101. ouistiti

    The remove filter line :

    remove_filter( ‘pre_term_description’, ‘wp_filter_kses’ );

    seems to have stopped working since WP 2.9. Now the only html shown that is entered in taxonomy descriptions are links, photos, captions e.t.c. no longer work.

    Do you know of a fix for this?

  102. ouistiti

    Sorry that was some confusing punctuation, I meant to say that only links work, while other html is now filtered out.

  103. ouistiti

    I fixed this myself if anyone else is having the same problem in 2.9…

    Add :

    remove_filter( ‘term_description’, ‘wp_kses_data’ );

    to your functions.php

    Justin, maybe you could add this to your article because as it stands the article doesn’t work for > 2.9

  104. Chrissie Brodigan

    Justin,

    Can you estimate the time you took to put the first version of the site with the taxonomy together, including the ramp-up/learning time.

    I’m getting ready to embark on a very project (both inspired by and using this tutorial!) and I’m wondering what I’m getting myself into.

    WP/PHP Fluency = strong

    :) CB

  105. pspnob

    where exactly you put this code????

    ID, 'taxonomy_name', 'Taxonomy Label: ', ', ', '' ); ?>?
  106. 5 reasons I recommend WordPress « Calin Don

    [...] A good article on custom taxonomies can be found at http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database. [...]

Leave a Reply

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

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