钩子文档

get_ancestors

💡 云策文档标注

概述

get_ancestors 是一个 WordPress 过滤器,用于修改给定对象的祖先 ID 数组。它允许开发者在获取对象祖先时自定义或过滤数据。

关键要点

  • 过滤器名称:get_ancestors
  • 参数:$ancestors(祖先 ID 数组)、$object_id(对象 ID)、$object_type(对象类型)、$resource_type(资源类型)
  • 用途:在 get_ancestors() 函数中应用,用于调整祖先数据
  • 版本历史:WordPress 3.1.0 引入,4.1.1 添加 $resource_type 参数

代码示例

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

注意事项

  • 此过滤器与 get_ancestors() 函数关联,位于 wp-includes/taxonomy.php 文件中
  • 使用时需确保参数类型正确,避免数据错误

📄 原文内容

Filters a given object’s ancestors.

Parameters

$ancestorsint[]
An array of IDs of object ancestors.
$object_idint
Object ID.
$object_typestring
Type of object.
$resource_typestring
Type of resource $object_type is.

Source

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

Changelog

Version Description
4.1.1 Introduced the $resource_type parameter.
3.1.0 Introduced.