get_attachment_taxonomies
函数
get_attachment_taxonomies ( $attachment, $output = 'names' )
- 参数
-
-
(int|array|object)
$attachment
Attachment ID, data array, or data object.- Required: 是
-
(string)
$output
Output type. ‘names’ to return an array of taxonomy names, or ‘objects’ to return an array of taxonomy objects. Default is ‘names’.- Required: 否
- Default: ‘names’
-
(int|array|object)
- 返回值
-
- (string[]|WP_Taxonomy[]) List of taxonomies or taxonomy names. Empty array on failure.
- 定义位置
-
-
wp-includes/media.php
, line 3648
-
wp-includes/media.php
- 引入
- 2.5.0
- 弃用
- –
Retrieves taxonomies attached to given the attachment.
function get_attachment_taxonomies( $attachment, $output = 'names' ) { if ( is_int( $attachment ) ) { $attachment = get_post( $attachment ); } elseif ( is_array( $attachment ) ) { $attachment = (object) $attachment; } if ( ! is_object( $attachment ) ) { return array(); } $file = get_attached_file( $attachment->ID ); $filename = wp_basename( $file ); $objects = array( 'attachment' ); if ( false !== strpos( $filename, '.' ) ) { $objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 ); } if ( ! empty( $attachment->post_mime_type ) ) { $objects[] = 'attachment:' . $attachment->post_mime_type; if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { foreach ( explode( '/', $attachment->post_mime_type ) as $token ) { if ( ! empty( $token ) ) { $objects[] = "attachment:$token"; } } } } $taxonomies = array(); foreach ( $objects as $object ) { $taxes = get_object_taxonomies( $object, $output ); if ( $taxes ) { $taxonomies = array_merge( $taxonomies, $taxes ); } } if ( 'names' === $output ) { $taxonomies = array_unique( $taxonomies ); } return $taxonomies; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。