Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterTaxonomy::get_sorted_termsprivateWC 1.0

Get terms sorted based on taxonomy type (hierarchical vs flat).

Method of the class: ProductFilterTaxonomy{}

No Hooks.

Returns

Array. Sorted terms array.

Usage

// private - for code of main (parent) class only
$result = $this->get_sorted_terms( $taxonomy, $taxonomy_counts, $hide_empty, $orderby, $order );
$taxonomy(string) (required)
Taxonomy slug.
$taxonomy_counts(array) (required)
Term counts with term_id as key.
$hide_empty(true|false) (required)
Whether to hide empty terms.
$orderby(string) (required)
Sort field (name, count, menu_order).
$order(string) (required)
Sort direction (ASC, DESC).

ProductFilterTaxonomy::get_sorted_terms() code WC 10.3.6

private function get_sorted_terms( $taxonomy, $taxonomy_counts, $hide_empty, $orderby, $order ) {
	if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
		$args = array(
			'taxonomy'   => $taxonomy,
			'hide_empty' => false,
		);

		if ( $hide_empty ) {
			$args['include'] = array_keys( $taxonomy_counts );
		}

		$terms = get_terms( $args );

		if ( is_wp_error( $terms ) || empty( $terms ) ) {
			return array();
		}

		return $this->sort_terms_by_criteria( $terms, $orderby, $order, $taxonomy_counts );
	}

	return $this->get_hierarchical_terms( $taxonomy, $taxonomy_counts, $hide_empty, $orderby, $order );
}