Automattic\WooCommerce\Internal\ProductFilters
TaxonomyHierarchyData::compute_ancestors
Compute ancestor chain for a term.
Метод класса: TaxonomyHierarchyData{}
Хуков нет.
Возвращает
Массив. Array of ancestor term IDs (bottom-up).
Использование
// private - только в коде основоного (родительского) класса $result = $this->compute_ancestors( $term_id, $parent_lookup ): array;
- $term_id(int) (обязательный)
- The term ID.
- $parent_lookup(массив) (обязательный)
- Parent relationships.
Код TaxonomyHierarchyData::compute_ancestors() TaxonomyHierarchyData::compute ancestors WC 11.0.1
private function compute_ancestors( int $term_id, array $parent_lookup ): array {
$ancestors = array();
$current_id = $term_id;
while ( isset( $parent_lookup[ $current_id ] ) && $parent_lookup[ $current_id ] > 0 ) {
$parent_id = $parent_lookup[ $current_id ];
$ancestors[] = $parent_id;
$current_id = $parent_id;
}
return $ancestors;
}