функция
since 3.4.0
term_is_ancestor_of()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
term_is_ancestor_of( int|object $term1, int|object $term2, string $taxonomy ): bool
Описание
Для обоих параметров можно использовать либо ID, либо объект термина.
Оригинал (английский)
You can use either an ID or the term object for both parameters.
Параметры
$term1
int|object
обязательный
ID или объект для проверки, является ли он родительским термином.
$term2
int|object
обязательный
Дочерний термин.
$taxonomy
string
обязательный
Имя таксономии, которой принадлежат $term1 и $term2.
Возвращаемое значение
bool
$term2 $term1
Исходный код
wp-includes/taxonomy.php:1685
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 );
}
История изменений
| Версия | Описание |
|---|---|
| 3.4.0 | Introduced. |

