我试图按子术语显示带有链接的帖子,并按父术语显示组库帖子和子术语。例如:
父术语1
父术语1
第1学期
第二学期
母学期2
第3学期
我收到的不是这封信,而是第6封信:
第1学期
第二学期
第三学期。。。
这是我当前的代码:
$all_terms = get_terms([\'taxonomy\' => \'course-category\', \'hide_empty\' => 1 ] );
if (!$all_terms){
$Content = \'<h2>no terms</h2>\';;
}
foreach ( $all_terms as $term ) { // external
$query = new WP_Query( [
\'post_status\' => \'publish\',
\'post_type\' => \'course\'
]);
if ( ! $query->have_posts() ) continue;
$Content .= \'<h3>\' . $term->name . \'</h3>\';
$Content .= "<div>";
while ( $query->have_posts() ) {// internal
$query->the_post();
$Content .= \'<li><a href="\'. get_permalink() .\'">\'. get_the_title() .\'</a></li>\';
}
$Content .= "</div>";
我真的不知道如何使用get\\u terms(),也许还有get\\u term\\u children()来处理这个问题。
请帮我解决这个问题。。。如果你能给我提些建议,我将不胜感激。谢谢