0

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; ?>
4
  • how is an episode post connected to a season post? Are episode posts children of a season post? I'm not seeing any code in your question for what you've tried so far
    – Tom J Nowell
    Commented Aug 13, 2022 at 16:26
  • @TomJNowell ive tried <?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"
    – MrLonely
    Commented Aug 13, 2022 at 16:41
  • can you edit that into your question using the 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
    – Tom J Nowell
    Commented Aug 13, 2022 at 16:42
  • I dont know how to connect episodes to seasons, i think thats the problem, ive also edited the question, thanks for helping me
    – MrLonely
    Commented Aug 14, 2022 at 2:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.