I run a video game news blog. When my staff writes a news article or a review, I would like them to be able to “assign” that post to a game (if applicable), so then I could have the single.php template call information on that game (title, boxart, publisher, release date, etc.) and display it in the sidebar. I thought this might involve a custom taxonomy so that it could be assigned to a post just like tags are.
But then I realized I also wanted those games to have full pages loaded with information. I initially thought to create a custom post type for pages, and using custom fields, I could call the game’s box art, show its release date, display any posts or reviews on that game and displaying them with brief excerpts, and using custom taxonomies to display the game’s publisher, developer, etc…
And THEN I realized I also wanted those publishers and developers to have their own pages as well. Description, location, links to articles involving them, lists of any games attributed to them… and so on.
None of these can be child pages of the other, since developers aren’t always permanently tied to any particular publisher, games are sometimes co-developed by multiple parties, etc.
I’m in a pickle, and can’t figure out how to re-organize my site. I really want to use all the new toys in WordPress to make the site I want, rather than WP limiting what I can do. Any suggestions? I’ve been brainstorming for days trying to figure something out. Any suggestions would be appreciated.
There are a few choices to go with this. I’ve actually gone through the same though process you have been. It would be easy if WordPress let you link posts or custom post types together but in lieu of that, the hackery of WordPress developers must occur!
The solution I went with in the plugin I’m working on is a bit hacky, but it works for me. Basically in my plugin, I wanted to have a post type called series that holds info on a particular tv series, a post type for episodes and another post type for DVD and Blu-ray releases. I wanted both the episode and releases post types to reference the series type they come from, so if I create a single series post page, it could list the episodes and releases as well as the series info.
My solution involves a custom field that holds the object id of the series. The first way to accomplish this was to create a metabox that had a select box of all the posts of type series:
The function get_select_array() basically takes a custom post type and returns the post titles and ID’s of all the ones that are published in an array. I then use that array to populate a select box. In my plugin, I’m using the metabox creation class created by Rilwis but I’ll post some code for you to use (code is adapted from Rilwis’s code):
This will add a metabox that has a select that lists all the series available. When the post is saved, the id of that series will be saved in a custom field called ‘parent_series’. Once that is done, you can call on that id and use it to call the series info via a custom query. Or its possible to do the opposite: on the series page, you do a query for all the episode pages that have the same value in their custom field/meta data.
And there you have it. Using this code you can link posts of one type to those of another, making them work like pseudo taxonomies in a way. I edited the code up pretty quickly so if you find any errors or bugs, let me know. If there are better ways to do this, please let me know 🙂