Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

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 dataI 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

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

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

Source Link
Michelle
  • 3.5k
  • 4
  • 26
  • 34

Too many nested wp_query loops in this hypothetical query?

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