Skip to content

Instantly share code, notes, and snippets.

@Dinamiko
Created March 8, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dinamiko/7887f67142efb82ba443 to your computer and use it in GitHub Desktop.
Save Dinamiko/7887f67142efb82ba443 to your computer and use it in GitHub Desktop.
/**
* 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