^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_attachment_taxonomies()用法示例

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$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()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈