如何不仅获得当前猫的条款,而且还获得它所有孩子的条款

时间:2012-08-08 作者:Bram

我正在修改一个主题以使用父分类术语而不是所有分类术语,现在我只能显示父分类术语,但现在我遇到了计数问题。

基本上,这是必须更改的代码

$_products_in_term = get_objects_in_term( $term->term_id, $taxonomy ); 
这将获取当前项的所有项,然后使用当前项进行截取,然后进行计数。现在,我如何修改这段代码,使其不仅能获得当前学期的学期,而且如果它有孩子,也能获得其所有孩子的学期,(只会深入一步,不会与孙子一起工作)

这是代码完整的代码

               foreach ($terms as $term) { 

                // Get count based on current view - uses transients
                $transient_name = \'wc_ln_count_\' . md5( sanitize_key($taxonomy) . sanitize_key( $term->term_id ) );

                if ( false === ( $_products_in_term = get_transient( $transient_name ) ) ) {

                //  $_products_in_term = get_objects_in_term( $term->term_id, $taxonomy );

                $args2[\'child_of\'] = $term->term_id;
                $terms = get_terms( $taxonomy , $args2 );
                $term_array=array();
                foreach($terms as $terms){
                $term_array[]= $terms->term_id;
                }

                $_products_in_term = get_objects_in_term( $term_array, $taxonomy ); 

                    set_transient( $transient_name, $_products_in_term );
                }

                $option_is_set = (isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy][\'terms\'])) ; 

                // If this is an AND query, only show options with count > 0
                if ($query_type==\'and\') {

                    $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->filtered_product_ids));

                    // skip the term for the current archive
                    if ( $current_term == $term->term_id ) continue; 

                    if ($count>0 && $current_term !== $term->term_id ) $found = true;

                    if ($count==0 && !$option_is_set) continue;

                // If this is an OR query, show all options so search can be expanded
                } else { 

                    // skip the term for the current archive
                    if ( $current_term == $term->term_id ) continue;

                    $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->unfiltered_product_ids));

                    if ($count>0) $found = true;

                }

1 个回复
最合适的回答,由SO网友:Rajeev Vyas 整理而成
$terms = get_term_children( $term->term_id , $taxonomy );
$term_array=array();
foreach($terms as $terms){
  $term_array[]= $terms;
}

$_products_in_term = get_objects_in_term( $term_array, $taxonomy ); 
结束

相关推荐

GET_USER_COUNT的输出何时变成数组?

questionget\\u user\\u count()的整数输出何时转换为数组?backgroundms函数中的函数get\\u user\\u count()。php返回一个整数(它调用get\\u site\\u选项(\'user\\u count\'))更新中的函数wp\\u version\\u check()。php将此整数存储在第55行的$user\\u count中紧接着,在第73行,它调用这个整数$user\\u count[\'total\\u users\']reason for