Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_attachment_taxonomies [ WordPress Function ]

get_attachment_taxonomies ( $attachment )
Parameters:
  • (int|array|object) $attachment Attachment ID, Attachment data array, or Attachment data object.
Returns:
  • (array) Empty array on failure. List of taxonomies on success.
Defined at:



Retrieve taxonomies attached to the attachment.

Source


<?php
function get_attachment_taxonomies($attachment) {
    if ( 
is_int$attachment ) )
        
$attachment get_post($attachment);
    else if ( 
is_array($attachment) )
        
$attachment = (object) $attachment;

    if ( ! 
is_object($attachment) )
        return array();

    
$filename basename($attachment->guid);

    
$objects = array('attachment');

    if ( 
false !== strpos($filename'.') )
        
$objects[] = 'attachment:' substr($filenamestrrpos($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) )
            
$taxonomies array_merge($taxonomies$taxes);

    return 
array_unique($taxonomies);
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics