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.
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):
View the code on Gist.
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:
View the code on Gist.
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.
View the code on Gist.
The result?
The card “Pikachu & Zekrom-GX” was printed into the Team Up set three times:
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!
Interested in having a custom taxonomy solution built for your website? Contact WebDevStudios today.
The post Hashing a Custom Taxonomy appeared first on WebDevStudios.