父母1-子女1-孙子1
我需要为我访问的每个学期显示任何当前学期的子学期(仅直接子学期)。仅适用于父级(show child1),但不适用于子级(不显示granchild1)
如何解决此问题?谢谢
$queried_object = get_queried_object();
$cpt = get_post_type( get_the_ID() );
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
echo \'cpt - \'.$cpt;
echo \'<br>tax - \'.$taxonomy;
echo \'<br>term id - \'.$term_id;
$customPostTaxonomies = get_object_taxonomies($cpt);
if ( $customPostTaxonomies ) {
foreach($customPostTaxonomies as $tax) {
$args = array(
\'orderby\' => \'name\',
\'hierarchical\' => 0,
\'taxonomy\' => $tax,
\'field\' => \'id\',
\'parent\'=> $term_id,
\'title_li\' => \'\'
);
wp_list_categories( $args );
}
UPDATE:
Structure:
cpt = corsi
tax = argomenti
tax_term = parent1
tax_term_child = child1
tax_term_child_granchild = grandchild1
最合适的回答,由SO网友:TheDeadMedic 整理而成
由于这是用于分类归档的,所以您可以使用get_queried_object()
以及parent
和depth
中的参数wp_list_categories()
:
$term = get_queried_object();
$list = wp_list_categories( array(
\'orderby\' => \'name\',
\'taxonomy\' => $term->taxonomy,
\'parent\' => $term->term_id,
\'title_li\' => \'\',
\'depth\' => 1,
\'echo\' => false,
));
if ( $list ) {
echo "<ul>$list</ul>";
} else {
// Nothing, do something else!
}
请注意
wp_list_categories()
不输出/返回包含
<ul />
, 因此,您需要自己这样做(如所示)。