Un motore di ricerca WordPress per sviluppatori e autori di temi



_get_term_hierarchy ›

Da2.3.0
Deprecaton/a
_get_term_hierarchy ( $taxonomy )
Accedi:
  • private
Parametri:
  • (string) $taxonomy Taxonomy name.
    Richiesto:
Ritorna:
  • (array) Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
Definito a:
Codex:

Retrieves children of taxonomy as Term IDs.



Sorgenti

function _get_term_hierarchy( $taxonomy ) {
	if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
		return array();
	}
	$children = get_option( "{$taxonomy}_children" );

	if ( is_array( $children ) ) {
		return $children;
	}
	$children = array();
	$terms    = get_terms(
		$taxonomy,
		array(
			'get'                    => 'all',
			'orderby'                => 'id',
			'fields'                 => 'id=>parent',
			'update_term_meta_cache' => false,
		)
	);
	foreach ( $terms as $term_id => $parent ) {
		if ( $parent > 0 ) {
			$children[ $parent ][] = $term_id;
		}
	}
	update_option( "{$taxonomy}_children", $children );

	return $children;
}