get_taxonomies_for_attachments

函数
get_taxonomies_for_attachments ( $output = 'names' )
参数
  • (string) $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'. Default 'names'.
    Required:
    Default: 'names'
返回值
  • (string[]|WP_Taxonomy[]) Array of names or objects of registered taxonomies for attachments.
相关
  • get_taxonomies()
定义位置
相关方法
get_taxonomiesget_the_attachment_linkwp_ajax_query_attachmentsget_taxonomy_labelsis_local_attachment
引入
3.5.0
弃用
-

get_taxonomies_for_attachments: 这个函数检索已注册的用于附件的分类法名称的数组。它不接受任何参数,并返回一个分类法名称的数组。

检索所有为附件注册的分类法。

处理特定邮件类型的分类法,如 attachment:image 和 attachment:video。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_taxonomies_for_attachments( $output = 'names' ) {
$taxonomies = array();
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
foreach ( $taxonomy->object_type as $object_type ) {
if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
if ( 'names' === $output ) {
$taxonomies[] = $taxonomy->name;
} else {
$taxonomies[ $taxonomy->name ] = $taxonomy;
}
break;
}
}
}
return $taxonomies;
}
function get_taxonomies_for_attachments( $output = 'names' ) { $taxonomies = array(); foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { foreach ( $taxonomy->object_type as $object_type ) { if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { if ( 'names' === $output ) { $taxonomies[] = $taxonomy->name; } else { $taxonomies[ $taxonomy->name ] = $taxonomy; } break; } } } return $taxonomies; }
function get_taxonomies_for_attachments( $output = 'names' ) {
	$taxonomies = array();

	foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
		foreach ( $taxonomy->object_type as $object_type ) {
			if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
				if ( 'names' === $output ) {
					$taxonomies[] = $taxonomy->name;
				} else {
					$taxonomies[ $taxonomy->name ] = $taxonomy;
				}
				break;
			}
		}
	}

	return $taxonomies;
}

常见问题

FAQs
查看更多 >