get_post_taxonomies()
云策文档标注
概述
get_post_taxonomies() 函数用于检索给定文章的所有分类法名称。它接受文章 ID 或 WP_Post 对象作为参数,返回一个包含分类法名称的数组。
关键要点
- 函数返回一个字符串数组,包含文章的所有分类法名称,如 category、post_tag 等。
- 参数 $post 可选,可以是文章 ID 或 WP_Post 对象,默认为全局 $post。
- 内部调用 get_post() 和 get_object_taxonomies() 来实现功能。
- 与 get_object_taxonomies() 的区别在于,后者可以返回分类法名称或对象数组,而 get_post_taxonomies() 仅返回名称数组。
代码示例
$taxonomy_names = get_post_taxonomies();
print_r( $taxonomy_names );
原文内容
Retrieves all taxonomy names for the given post.
Parameters
Source
function get_post_taxonomies( $post = 0 ) {
$post = get_post( $post );
return get_object_taxonomies( $post );
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
Skip to note 3 content
Codex
Displays all taxonomies of a post.
Output:
Array ( [0] => category [1] => post_tag [2] => post_format )Skip to note 4 content
deeptiboddapati
#return section should say that the function returns an array of all taxonomy names for the given post or post object instead of just an array.
This highlights the main point of difference between get_post_taxonomies and get_object_taxonomies which can return an array of all taxonomy names or an array of all taxonomy objects.
https://codex.wordpress.org/Function_Reference/get_post_taxonomies
https://developer.wordpress.org/reference/functions/get_object_taxonomies/