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 attempting something more complex than I've ever done before with WordPress, so please forgive me if this question doesn't make sense.

I have a Books archive page and want it to display excerpts from my custom post type "Books", sorted first by Genre, then by Series, then by Reading Order. So it would look like this:

Historical GENRE

--- My First Historical SERIES; SERIES description;

------BOOK 1, BOOK 2, BOOK 3

--- My Second Historical SERIES; SERIES description;

------BOOK 1, BOOK 2, BOOK 3

Contemporary GENRE

... ETC

I have gone back and forth on how to set up my data. Right now, I'm set up like this:

"Series" is a Custom Post Type with custom fields "Genre" and "Description";

"Books" is a Custom Post Type with custom fields for "Series" (dropdown list populated by currently published Series) and Reading Order (a number).

So conceptually, this is the code I think I need to do to display my Books Archive page:

  1. WP_Query to select all custom-post-type-SERIES sorted by custom field GENRE;

  2. For each GENRE, display Genre name if not different from previous Genre name;

  3. Display SERIES name and description;

  4. NEW query to select all custom-post-type-BOOKS with parent ID of current custom-post-type-SERIES, sorted by custom field READING ORDER;

  5. When that query is done, display next SERIES name/description and repeat from 4;

  6. When there are no more SERIES with current custom-field GENRE, display next GENRE name and repeat from 2.

This seems like a ton of queries though. Before I go write all the code, can you tell me if there's a better way to either think about this or organize my content? Thank you so much!!

Michelle

share|improve this question

1 Answer 1

up vote 1 down vote accepted

When you need to retrieve and present a lot of information there is bound to be complexity. Mostly it is finding right balance between complex querying and complex sorting in PHP (which is often overlooked option).

Your logic looks mostly fine, what could use tweaking as for me:

  • Genre seems more like a taxonomy than custom field;

  • you are essentially building post relationships here and might be better of just using one of relationships plugins, rather than trying to handle it with custom fields. It seems easy enough now, but add more CPTs into the mix and it might fall apart.

share|improve this answer
    
Thanks Rarst!! I did have Genre as a taxonomy originally, but then learned WP isn't set up to orderby taxonomy terms. Since there will only ever be 3 or 4 genres for this site, custom fields seemed like the easier way to go. Post2Post is the only post-relationship plugin I know (though I haven't tried it), do you have others you'd recommend? Thanks again! –  Michelle Sep 12 '11 at 21:00
    
Yep, sorting by taxonomy is not recommended... But take it as a hint rather than challenge. :) P2P is considered solid and common choice. I usually deal with custom solutions myself and don't have much experience with public relationship plugins. –  Rarst Sep 12 '11 at 21:08

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.