wpseek.com
WordPress开发者和主题制作者的搜索引擎
get_attachment_taxonomies › WordPress Function
Since2.5.0
已弃用n/a
› get_attachment_taxonomies ( $attachment, $output = 'names' )
参数: (2) |
|
返回: |
|
定义在: |
|
文档: | |
Change Log: |
|
Retrieves taxonomies attached to given the attachment.
Related Functions: get_the_taxonomies, get_attachment_icon, get_attachment_icon_src, get_object_taxonomies, get_post_taxonomies
源码
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 ( str_contains( $filename, '.' ) ) { $objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 ); } if ( ! empty( $attachment->post_mime_type ) ) { $objects[] = 'attachment:' . $attachment->post_mime_type; if ( str_contains( $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; }