Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

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.).

share|improve this answer
    
Hi, yes -- rooms are assigned on a year-to-year basis. I considered using custom fields, but they could easily become very bloated. I ended up using Posts 2 Posts, which allowed me to create relationships between the various CPTs I have created: Residents, Rooms, Parking spaces and Leadership positions. I've basically just added a meta field "year" for each of these relationships, which the user can specify when they create the relationships in the back-end. This works brilliantly simple. Thanks in any case for your answer! –  Johannes Dec 17 '12 at 20:54
    
@Johannes: You can accept his answer if it solved your problem by clicking the checkmark next to the answer. –  guiniveretoo Nov 22 '13 at 19:04
add comment

It can be done with the help of custom taxonomy easily you just need to create create three taxonomies Year, Rooms and Parking space and then you can filter the results by any value in you query_posts

add_action('init', 'custom_taxonomy');
function custom_taxonomy(){
register_taxonomy("years", 'post_type_slug', array("hierarchical" => true, "label" => "Years", "singular_label" => "Years","rewrite" => true) );
register_taxonomy("rooms", 'post_type_slug', array("hierarchical" => true, "label" => "Rooms", "singular_label" => "Rooms","rewrite" => true) );
register_taxonomy("parking", 'post_type_slug', array("hierarchical" => true, "label" => "Parkings", "singular_label" => "Parking","rewrite" => true) );
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.