get_attachment_taxonomies( int|array|object $attachment, string $output = 'names' )
Retrieves taxonomies attached to given the attachment.
描述
参数
- $attachment
-
(int|array|object)
(Required)
Attachment ID, data array, or data object. - $output
-
(string)
(Optional)
Output type. ‘names’ to return an array of taxonomy names, or ‘objects’ to return an array of taxonomy objects. Default is ‘names’.Default value: ‘names’
返回值
(array) Empty array on failure. List of taxonomies on success.
源代码
File: wp-includes/media.php
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 = 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 ) {
if ( $taxes = get_object_taxonomies( $object, $output ) ) {
$taxonomies = array_merge( $taxonomies, $taxes );
}
}
if ( 'names' === $output ) {
$taxonomies = array_unique( $taxonomies );
}
return $taxonomies;
}
更新日志
Version | 描述 |
---|---|
4.7.0 | Introduced the $output parameter. |
2.5.0 | Introduced. |
相关函数
Uses
-
wp-includes/taxonomy.php:
get_object_taxonomies() -
wp-includes/post.php:
get_post() -
wp-includes/post.php:
get_attached_file()
Used By
-
wp-admin/includes/media.php:
get_attachment_fields_to_edit() -
wp-admin/includes/media.php:
get_compat_media_markup() -
wp-admin/includes/media.php:
media_upload_form_handler() -
wp-admin/includes/ajax-actions.php:
wp_ajax_save_attachment_compat() -
wp-includes/taxonomy.php:
get_object_taxonomies()
你可能对这些文章感兴趣:
- wordpress函数get_the_posts_navigation()用法示例
- wordpress函数get_the_title()用法示例
- wordpress函数get_the_terms()用法示例
- wordpress函数get_the_tags()用法示例
- wordpress函数get_the_taxonomies()用法示例
- wordpress函数get_the_permalink()用法示例
- wordpress函数get_the_password_form()用法示例
- wordpress函数get_the_posts_pagination()用法示例
- wordpress函数get_the_modified_date()用法示例
- wordpress函数get_the_modified_time()用法示例
- wordpress函数get_the_modified_author()用法示例
- wordpress函数get_the_guid()用法示例
- wordpress函数get_the_ID()用法示例
- wordpress函数get_the_excerpt()用法示例
如有疑问,请前往问答中心反馈!
反馈