您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取祖先ID函数:get_ancestors

时间:2024-03-10

WordPress函数get_ancestors可以用于获取分类的祖先ID,或页面的祖先ID,包括所有的上级。

get_ancestors( int $object_id, string $object_type = '', string $resource_type = '' )

函数参数

$object_id

整数

对象ID

$object_type

字符串

对象类型,可用值:page、post、category或其他分类法名称

$resource_type

字符串

资源的类型,可用值:post_type、taxonomy

函数使用示例

获取ID为7的分类的所有祖先分类:

$ids = get_ancestors(7, 'category');

获取ID为15的所有祖先页面:

$ids = get_ancestors(15, 'page');

扩展阅读

get_ancestors()函数位于:wp-includes/taxonomy.php

相关函数:

  • get_term()

  • get_term_parents_list()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 ytldj.com


Whatsapp
Powered by RRZCMS