get_object_taxonomies
函数
get_object_taxonomies ( $object, $output = 'names' )
- 参数
-
-
(string|string[]|WP_Post)
$object
Name of the type of taxonomy object, or an object (row from posts)- Required: 是
-
(string)
$output
Optional. The type of output to return in the array. Accepts either ‘names’ or ‘objects’. Default ‘names’.- Required: 否
- Default: ‘names’
-
(string|string[]|WP_Post)
- 返回值
-
- (string[]|WP_Taxonomy[]) The names or objects of all taxonomies of `$object_type`.
- 定义位置
-
-
wp-includes/taxonomy.php
, line 272
-
wp-includes/taxonomy.php
- 引入
- 2.3.0
- 弃用
- –
Returns the names or objects of the taxonomies which are registered for the requested object or object type,
such as a post object or post type name.
Example:
$taxonomies = get_object_taxonomies( ‘post’ );
This results in:
Array( ‘category’, ‘post_tag’ )
function get_object_taxonomies( $object, $output = 'names' ) { global $wp_taxonomies; if ( is_object( $object ) ) { if ( 'attachment' === $object->post_type ) { return get_attachment_taxonomies( $object, $output ); } $object = $object->post_type; } $object = (array) $object; $taxonomies = array(); foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { if ( array_intersect( $object, (array) $tax_obj->object_type ) ) { if ( 'names' === $output ) { $taxonomies[] = $tax_name; } else { $taxonomies[ $tax_name ] = $tax_obj; } } } return $taxonomies; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。