I have a confession. I like Pokémon.

It’d really be more accurate to say I never stopped liking it. Sure, there was that point when it wasn’t “cool” anymore and I was too busy trying to be “cool,” but this is the kind of thing that just sticks with me. So, naturally, I’ve built up a collection of Pokémon cards. And what does someone like me do when they have a collection of something?

Build a WordPress-based database site for cataloging it, of course! This is where hashing a custom taxonomy comes into the picture.

My current plan revolves around taking the card information from the third-party Pokémon TCG Developers API and combining it with the pricing information from TCGplayer. This will allow me to store information of not just every card I have, but every version of every card I have. The most common version is the reverse holographic printing (shown below). Other versions, especially rare, powerful cards, can include full-art versions, alternate-art printings, and even rainbow-colored “secret rare” cards.

Two printings of the Komala card, one normal and the other reverse holographic.
Two printings of the Komala card, one normal and the other reverse holographic.

 

The trick, however, is that in addition to being collectibles, Pokémon cards are also part of a game. All of these different versions of each card mean something different when it comes to collecting and pricing, but they’re the exact same card when it comes to playing the game. So while I want to be able to appreciate and track my collection in all its myriad forms, I need to be able to see what cards are the same from a game-play perspective.

In WordPress terms, we have a custom post type for cards. These cards need to be linked together if the cards are the same from a game-play perspective. This sounds like a job for a custom taxonomy!

First, here’s a peek at our custom post type (using OOPS-WP to organize things):

Because some cards can have the same title but not be the same card, we need to match on something other than title. For this project, I’ve decided to use our old friend, the MD5 hash.

While it’s not useful for passwords anymore, MD5 hash is still useful for quickly determining if two things are the same. I’ll be hashing the relevant information from cards as I import them and storing that data in a non-hierarchical custom taxonomy (like a post tag). This should allow me to not only find alternate printings of cards within a set but also find cards from the past that have been reprinted in the present.

We start with our custom taxonomy:

Finally, here’s the relevant part of the import code. I’m using the PokemonTCG SDK to call the API and import the information into my WordPress install. As I do that, I’m storing the title and card text in a string that I will then hash and store in the custom taxonomy I’ve made.

The result?

Screenshot of WP backend showing three Cards named Pikachu & Zekrom-GX

The card “Pikachu & Zekrom-GX” was printed into the Team Up set three times:

  1. The normal printing
  2. The “Full Art” printing
  3. The “Secret Rare” printing

Because they all have the same title and text, they all have the same hash and thus are all grouped together by the custom taxonomy. Now, the next logical step is to surface this information on the frontend of the website. But that will have to in another blog post—mostly because I haven’t written the frontend yet. If you want to follow along, all my code is on GitHub. Until next time, keep having fun!

Animated gif of Pikachu

Interested in having a custom taxonomy solution built for your website? Contact WebDevStudios today.

Comments

1 thought on “Hashing a Custom Taxonomy

  1. Wow, this is like you wrote it from my mind! I’ve been trying to work on my own Pokedex for years now. I’ve got the code receipts on my server too for those curious. Thanks for writing this article – now I’m one step closer to making mine a reality!

Have a comment?

Your email address will not be published. Required fields are marked *

accessibilityadminaggregationanchorarrow-rightattach-iconbackupsblogbookmarksbuddypresscachingcalendarcaret-downcartunifiedcouponcrediblecredit-cardcustommigrationdesigndevecomfriendsgallerygoodgroupsgrowthhostingideasinternationalizationiphoneloyaltymailmaphealthmessagingArtboard 1migrationsmultiple-sourcesmultisitenewsnotificationsperformancephonepluginprofilesresearcharrowscalablescrapingsecuresecureseosharearrowarrowsourcestreamsupporttwitchunifiedupdatesvaultwebsitewordpress