Created
March 8, 2015 10:48
-
-
Save Dinamiko/7887f67142efb82ba443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Obtiene el id del attachment a partir del id de la categoría | |
* @param string taxonomy name | |
* @param int term id | |
* @return int attachment id | |
*/ | |
function ic_get_attachment_id( $taxonomy = 'category', $term_id ) { | |
$args = array( | |
'post_type' => 'attachment', | |
'numberposts' => -1, | |
'post_status' => null, | |
'tax_query' => array( | |
array( | |
'taxonomy' => $taxonomy, | |
'field' => 'id', | |
'terms' => array( $term_id ) | |
) | |
) | |
); | |
$attachments = get_posts( $args ); | |
foreach ( $attachments as $attachment ) { | |
$id = $attachment->ID; | |
} | |
return $id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment