Automattic\WooCommerce\Internal\ProductFilters
TaxonomyHierarchyData::compute_descendants
Compute all descendants of a term.
Method of the class: TaxonomyHierarchyData{}
No Hooks.
Returns
Array. Array of descendant term IDs.
Usage
// private - for code of main (parent) class only $result = $this->compute_descendants( $term_id, $children ): array;
- $term_id(int) (required)
- The term ID.
- $children(array) (required)
- Children relationships map.
TaxonomyHierarchyData::compute_descendants() TaxonomyHierarchyData::compute descendants code WC 10.3.3
private function compute_descendants( int $term_id, array $children ): array {
$descendants = array();
if ( ! isset( $children[ $term_id ] ) ) {
return $descendants;
}
foreach ( $children[ $term_id ] as $child_id ) {
$descendants[] = $child_id;
$descendants = array_merge( $descendants, $this->compute_descendants( $child_id, $children ) );
}
return array_unique( $descendants );
}