I am trying to format a custom post type for a "series". Each post is an Episode, each Episode belongs to a Season, and each Season belongs to a series (just like a TV show).
I have the following:
- Custom Post type: "Episodes"
- Custom Taxonomy: "Series"
- Inside Series, parent category of "Real Deal"
- Inside "Real Deal" category, several subcategories (IE "Season 1", "Season 2" ..)
- Inside Series, parent category of "Real Deal"
I need to be able to select my "Episodes" both by Series (IE, "Real Deal" in the above), as well as by Season (IE, "Season 1" of Real Deal).
An image speaks a thousand words so here's a quick mockup of what I mean:
WHAT I'VE TRIED
Here's the code I currently have, however I don't think I'm on the right track for doing what I've illustrated above. This will get me all the Episodes for Season 1, However I need to get all the episodes for every season, and then group each season into it's own HTML container.
<?php
$args = [
'post-type' => 'episode',
'post-status' => 'publish',
'tax_query' => [
[
'taxonomy' => 'series',
'field' => 'slug',
'terms' => 'season-1'
]
]
];
$episodes = new WP_Query($args);
if ( $episodes->have_posts() ) {
while( $episodes->have_posts() ) {
$episodes->the_post();
get_template_part('content','episodes');
}
} else {
get_template_part('content', 'none');
}
?>
QUESTION
How can I structure my Query to A) Select all episodes, grouped by Series, then displayed by season?
EDIT:
I ended up using the 3rd code snippet provded by Michael Ecklund, it managed to accomplish exactly what I was looking for -- grabbing the 4 most recent posts in each season, and storing them into an array. Thank you for your help!