Uses
| Uses | Description |
|---|---|
| wp-includes/taxonomy.php: term_is_ancestor_of() | Check if a term is an ancestor of another term. |
| wp-includes/taxonomy.php: get_term() | Get all Term data from database by Term ID. |
Check if a term is an ancestor of another term.
You can use either an ID or the term object for both parameters.
(int|object) (Required) ID or object to check if this is the parent term.
(int|object) (Required) The child term.
(string) (Required) Taxonomy name that $term1 and $term2 belong to.
(bool) Whether $term2 is a child of $term1.
File: wp-includes/taxonomy.php
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 );
} | Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/term_is_ancestor_of