get_taxonomies_for_attachments

The timeline below displays how wordpress function get_taxonomies_for_attachments has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves all of the taxonomies that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 *
 * @see get_taxonomies()
 *
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 *                       Default 'names'.
 * @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
 */
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;
}

WordPress Version: 5.5

/**
 * Retrieves all of the taxonomies that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 *
 * @see get_taxonomies()
 *
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 *                       Default 'names'.
 * @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
 */
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;
}

WordPress Version: 5.3

/**
 * Retrieves all of the taxonomies that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 * @see get_taxonomies()
 *
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 *                       Default 'names'.
 * @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
 */
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;
}

WordPress Version: 5.1

/**
 * Retrieves all of the taxonomies that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 * @see get_taxonomies()
 *
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 *                       Default 'names'.
 * @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
 */
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;
}

WordPress Version: 4.2

/**
 * Retrieves all of the taxonomy names that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 *
 * @see get_taxonomies()
 *
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 *                       Default 'names'.
 * @return array The names of all taxonomy of $object_type.
 */
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;
}

WordPress Version: 4.1

/**
 * Return all of the taxonomy names that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 * @see get_attachment_taxonomies()
 *
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 * @return array The names of all taxonomy of $object_type.
 */
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;
}

WordPress Version: 3.7

/**
 * Return all of the taxonomy names that are registered for attachments.
 *
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
 *
 * @since 3.5.0
 * @see get_attachment_taxonomies()
 * @uses get_taxonomies()
 *
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 * @return array The names of all taxonomy of $object_type.
 */
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;
}