I'm modding a theme to use parent taxonomy terms instead of all taxonomy terms, now I've been able to only display the parents, but now I've run into a count problem.
Basicly this is the code that has to be changed
$_products_in_term = get_objects_in_term( $term->term_id, $taxonomy );
This gets all the terms of the current term, which then later is used to do an intercept with and then count. Now how could I mod this code to not only get the terms of the current term but if it has children get the terms of all its children , (will only go 1 deep, not gonna work with grandchildren)
This is the code the full code
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;
}