我正在使用$custom_terms = get_term_children( $term_id, $taxonomy_name );
显示当前分类术语的子术语。我想做的是排除第四级术语,因为我不想显示它们,也不想显示我迄今为止尝试过的任何内容\'hide_empty\'
和\'parent\'
没有为我工作过。
我发现这个问题与我想做的相似:https://stackoverflow.com/questions/28079153/wp-query-exclude-all-terms-of-a-custom-taxonomy
我不想明确声明要排除哪些术语,因为它们太多了,客户可能会添加更多。我需要它是动态的,并且不显示当前分类法的第四级术语。
我的分类有4个层次:
级别1>级别2>级别3>级别4
以下是我目前的代码:
$term_id = get_queried_object()->term_id;
$taxonomy_name = \'product_range\';
$custom_terms = get_term_children( $term_id, $taxonomy_name );
foreach($custom_terms as $custom_term) {
$term = get_term_by( \'id\', $custom_term, $taxonomy_name );
wp_reset_query();
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_range\',
\'field\' => \'slug\',
\'terms\' => $term->slug,
\'parent\' => 0
),
),
);
}