So i have 2 custom post types, Shows and Episodes. I want when im on example.com/show/better-call-saul, to group episodes by seasons for example:
-Season 1
.Episode 1
.Episode 2
.Episode 3
-Season 2
.Episode 1
.Episode 2
.Episode 3
Ive tried grouping by category for example, each episode need to be in category: Season 1 or Season 4, but that doesnt work so well or i dont know how do it properly. What structure would you have? what i need do add to make it work?
Do i need to add another post type, like "Seasons" ?
<?php
$terms = get_terms( array(
"taxonomy" => "category",
) );
foreach ($terms as $term) :
$posts = get_posts(["post_type" => "episodes", "cat" => $term->term_id]);
?>
<h4><?= $term->name; ?></h4>
<ul>
<?php foreach($posts as $post) : ?>
<p>
<?= $post->post_title; ?>
</p>
<img src="<?php the_post_thumbnail_url( ); ?>" alt="<?php the_title( ); ?>">
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
<?php $terms = get_terms( array( "taxonomy" => "category", ) ); foreach ($terms as $term) : $posts = get_posts(["post_type" => "episodes", "cat" => $term->term_id]); ?> <h4><?= $term->name; ?></h4> <ul> <?php foreach($posts as $post) : ?> <p> <?= $post->post_title; ?> </p> <img src="<?php the_post_thumbnail_url( ); ?>" alt="<?php the_title( ); ?>"> <?php endforeach; ?> </ul> <?php endforeach; ?>
But it gives me all the episodes that is in the category "Season 1"Edit
link rather than posting it as a comment? Blocks of code don't work in comments. Also did you see my other questions? Try to answer all of them to avoid back and forth, make your question as complete and specific as possible