根据评论,您应该能够执行以下操作:
创建一个自定义分类法来保存您的Temporadora项目(例如Temporadora 1)创建一个自定义帖子类型来保存您的剧集,然后在这两者之间创建一个关系,应该执行以下操作:
$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>";
}
}
}
这应该按顺序抓取所有的temporadora分类项目,然后为每个项目抓取并打印出每个相关的插曲。
供参考: