Title: get_ancestors
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘get_ancestors’, int[] $ancestors, int $object_id, string $object_type, string $resource_type )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#wp--skip-link--target)

Filters a given object’s ancestors.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#parameters)󠁿

 `$ancestors`int[]

An array of IDs of object ancestors.

`$object_id`int

Object ID.

`$object_type`string

Type of object.

`$resource_type`string

Type of resource $object_type is.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#source)󠁿

    ```php
    return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/taxonomy.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/taxonomy.php#L5030)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/taxonomy.php#L5030-L5030)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#related)󠁿

| Used by | Description | 
| [get_ancestors()](https://developer.wordpress.org/reference/functions/get_ancestors/)`wp-includes/taxonomy.php` |

Gets an array of ancestor IDs for a given object.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/get_ancestors/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.1.1](https://developer.wordpress.org/reference/since/4.1.1/) | Introduced the `$resource_type` parameter. | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fget_ancestors%2F)
before being able to contribute a note or feedback.