Summery Summery

Check if a term is an ancestor of another term.

Syntax Syntax

term_is_ancestor_of( int|object $term1, int|object $term2, string $taxonomy )

Description Description

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

Parameters 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.

Return Return

(bool) Whether $term2 is a child of $term1.

Source Source

File: wp-includes/taxonomy.php

	$where             = 't.slug = %s';
	$else_where        = 't.name = %s';
	$where_fields      = array( $slug );
	$else_where_fields = array( $term );
	$orderby           = 'ORDER BY t.term_id ASC';
	$limit             = 'LIMIT 1';
	if ( ! empty( $taxonomy ) ) {
		if ( is_numeric( $parent ) ) {
			$parent              = (int) $parent;
			$where_fields[]      = $parent;
			$else_where_fields[] = $parent;
			$where              .= ' AND tt.parent = %d';
			$else_where         .= ' AND tt.parent = %d';

		$where_fields[]      = $taxonomy;
		$else_where_fields[] = $taxonomy;


Changelog Changelog

Version Description
3.4.0 Introduced.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.