Based on the comments, you should be able to do something like the following:
- Create a custom taxonomy to hold your Temporadora items in (e.g. Temporadora 1)
- Create a custom post type to hold your episodes
- Create a relationship between the two
From there, it should be a matter of doing something like the following:
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true
);
$temporadoras = get_terms('temporadora', $args);
if ( is_wp_error( $temporadoras ) ) {
echo "<p>Error!</p><pre>" . print_r( $temporadoras, true ) . "</pre>";
} else {
foreach ( $temporadoras as $temporadora ) {
$post_args = array(
'post_type' => 'episode',
'tax_query' => array(
array(
'taxonomy' => 'temporadora',
'terms' => $temporadora->term_id
)
),
'posts_per_page' => -1,
'orderby' => 'name',
'order' => 'ASC'
);
$post_list = new WP_Query( $post_args );
if ( $post_list->have_posts() ) {
while ( $post_list->have_posts() ) {
$episode = $post_list->next_post();
echo "<p>Found Posts:</p><pre>" . print_r($episode, true) . "</pre>";
}
} else {
echo "<p>None found for temporadora:</p><pre>" . print_r($temporadora, true) . "</pre>";
}
}
}
That should grab all of the temporadora taxonomy items in order then, for each of them, grab and print out each related episode.
For reference: