Custom taxonomy: same terms, but for different years

I’m building a directory of people in a boarding house. What I’d like to do, is to be able to assign the following metadata to each person:

  1. Room number
  2. Parking space number
  3. Leadership positions

The catch is that each of these are linked to a specific year, i.e.:

  • In 2010, John Smith lives in Room 2, has parking space 5 and is on
    the house council.
  • In 2011, John Smith lives in Room 42, has parking
    space 1 and is the house leader.

In addition, I need to be able to view people according to these properties, i.e. I want to see a list of all “house council” members or all people that have lived in Room 1.

My initial idea was to create a custom post type “Residents”, with a custom (hierarchical) taxonomy “Metadata”, which would have the following terms:

  • 2010
    • Room
      • 40
      • 41
      • 42
      • etc
    • Parking space
      • 1
      • 2
      • 3
      • etc
    • Leadership
      • House leader
      • House council
      • Section monitor
  • 2011
    • Room
      • (as above)
    • Parking space
      • (as above)
    • Leadership
      • (as above)

While this would allow me to filter residents according to room, parking space and leadership in a specific year, I’d like to be able to filter residents by a room number for all years, i.e.: instead of viewing all residents that lived in Room 2 in 2010 (which is merely a case of filtering according to 2010 > Room number > 2), I’d like to be able to view all residents that lived in Room 2 over the past 10 years.

Is this just a case of finding a sidebar widget that would allow me to select a specific sub-term from multiple parent terms in the “Metadata” taxonomy (e.g. selecting “Room 1” from “2010”, “2011”, “2012”, etc.) or is there a bigger architectural fallacy involved here?

Please let me know if I’m unclear on anything. Thanks in advance!

2 Answers
2

You could indeed, achieve everything with categories, but is it a good idea? If all main categories are 2010, 2011, 2012 and each of them has subcategories named Room1, Room2, etc., you would indeed have an easy way to make your searches by year or by room. The search by year would be as simple as querying the corresponding category. The search by room would imply to first create an array or a list of cat numbers by looping through all categories to find all categories named “Room1” or “Room2” for all the years. With the list in hands, the search would be very easy to execute.
All this is fine and could be implemented quickly.
The only fear I have for you is that this solution is really a hack and not very “logical” condisering your data model. First: are rooms only assigned every year? Do they not get assigned by periods?
Repeating categories like this is not a clean way to represent data because you would be repeating information. A better idea would be to create custom post types for Rooms, Parkings, etc., and assign them to users for each year, for example associating a year and a facility through a custom field. All custom fields have unique IDs, using the same primary key as posts, so they are always clearly separated. So you could perfectly have fields associating a year and the ID of a facility with something like Y2010:F223 (223 being the ID of the parking place, etc.). Then it would be easy to make a search using the custom field values (searching for Y2010, Y2011 or F21, etc.).

Leave a Comment