wpseek.com
Un motore di ricerca WordPress per sviluppatori e autori di temi



term_is_ancestor_of › WordPress Function

Da3.4.0
Deprecaton/a
term_is_ancestor_of ( $term1, $term2, $taxonomy )
Parametri: (3)
  • (int|object) $term1 ID or object to check if this is the parent term.
    Richiesto:
  • (int|object) $term2 The child term.
    Richiesto:
  • (string) $taxonomy Taxonomy name that $term1 and `$term2` belong to.
    Richiesto:
Ritorna:
  • (bool) Whether `$term2` is a child of `$term1`.
Definito a:
Codex:

Checks if a term is an ancestor of another term.

You can use either an ID or the term object for both parameters.


Sorgenti

function term_is_ancestor_of( $term1, $term2, $taxonomy ) {
	if ( ! isset( $term1->term_id ) ) {
		$term1 = get_term( $term1, $taxonomy );
	}
	if ( ! isset( $term2->parent ) ) {
		$term2 = get_term( $term2, $taxonomy );
	}

	if ( empty( $term1->term_id ) || empty( $term2->parent ) ) {
		return false;
	}
	if ( $term2->parent === $term1->term_id ) {
		return true;
	}

	return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy );
}