Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created April 28, 2012 00:31
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 emersonbroga/2514637 to your computer and use it in GitHub Desktop.
Save emersonbroga/2514637 to your computer and use it in GitHub Desktop.
Emerson Carvalho.com >> Buscar imagens/anexos do post no WordPress (snippet 1)
<?php
function busca_anexos_post( array $args )
{
$result = array();
$defaults = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
//ID do post que possui os anexos.
'post_parent' => null,
//Tamanhos default de imagens do wordpress thumbnail,medium, large, full
'size' => 'thumbnail'
);
$args = array_merge($defaults,$args);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$image_scr = wp_get_attachment_image_src( $attachment->ID , $args['size'] );
array_push($result, $image_scr);
}
}
return $result;
}
?>
//Exemplo de uso
<?php
$imagens = busca_anexos_post( array( post_parent => 1, 'size' => 'medium') );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment