Title: get_taxonomies_for_attachments
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_taxonomies_for_attachments( string $output = ‘names’ ): string[]|󠀁[WP_Taxonomy](https://developer.wordpress.org/reference/classes/wp_taxonomy/)󠁿[]

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#wp--skip-link--target)

Retrieves all of the taxonomies that are registered for attachments.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#description)󠁿

Handles mime-type-specific taxonomies such as attachment:image and attachment:video.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#see-also)󠁿

 * [get_taxonomies()](https://developer.wordpress.org/reference/functions/get_taxonomies/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#parameters)󠁿

 `$output`stringoptional

The type of taxonomy output to return. Accepts `'names'` or `'objects'`.
 Default`'
names'`.

Default:`'names'`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#return)󠁿

 string[]|[WP_Taxonomy](https://developer.wordpress.org/reference/classes/wp_taxonomy/)[]
Array of names or objects of registered taxonomies for attachments.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#source)󠁿

    ```php
    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 || str_starts_with( $object_type, 'attachment:' ) ) {
    				if ( 'names' === $output ) {
    					$taxonomies[] = $taxonomy->name;
    				} else {
    					$taxonomies[ $taxonomy->name ] = $taxonomy;
    				}
    				break;
    			}
    		}
    	}

    	return $taxonomies;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/media.php#L4226)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/media.php#L4226-L4243)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#related)󠁿

| Uses | Description | 
| [get_taxonomies()](https://developer.wordpress.org/reference/functions/get_taxonomies/)`wp-includes/taxonomy.php` |

Retrieves a list of registered taxonomy names or objects.

  |

| Used by | Description | 
| [wp_ajax_query_attachments()](https://developer.wordpress.org/reference/functions/wp_ajax_query_attachments/)`wp-admin/includes/ajax-actions.php` |

Handles querying attachments via AJAX.

  | 
| [WP_Media_List_Table::get_columns()](https://developer.wordpress.org/reference/classes/wp_media_list_table/get_columns/)`wp-admin/includes/class-wp-media-list-table.php` |  | 
| [WP_Query::get_posts()](https://developer.wordpress.org/reference/classes/wp_query/get_posts/)`wp-includes/class-wp-query.php` |

Retrieves an array of posts based on query variables.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_taxonomies_for_attachments/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_taxonomies_for_attachments%2F)
before being able to contribute a note or feedback.