Created
April 28, 2012 00:31
-
-
Save emersonbroga/2514637 to your computer and use it in GitHub Desktop.
Emerson Carvalho.com >> Buscar imagens/anexos do post no WordPress (snippet 1)
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
<?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