term_is_ancestor_of

函数


term_is_ancestor_of ( $term1, $term2, $taxonomy )
参数
  • (int|object)
    $term1
    ID or object to check if this is the parent term.
    Required:
  • (int|object)
    $term2
    The child term.
    Required:
  • (string)
    $taxonomy
    Taxonomy name that $term1 and `$term2` belong to.
    Required:
返回值
  • (bool) Whether `$term2` is a child of `$term1`.
定义位置
  • wp-includes/taxonomy.php
    , line 1603
引入
3.4.0
弃用

Checks if a term is an ancestor of another term.

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

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 );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。