I really hope this is a facepalm moment, b/c i'm getting frustrated with this. Making a quick loop to show certain attachment images. lifted it almost straight from the codex but wp_get_attachment_image() isn't behaving like I'd expect.
isn't the ID part of the wp_get_attachment_image the ID of the attachment? is that not the same as the post id of the attachment?
$args = array(
'post_type' => 'attachment',
'post_mime_type' => array('image','image/jpeg','image/png','image/gif'),
'numberposts' => 5,
'order' => 'ASC',
'orderby' => 'post_title'
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'full' , true);
echo '<p>' . $attachment->post_title . '</p>';
}
}
prints out the post titles but no images.
EDIT 1: yes I am definitely getting posts with my get_posts
some more debugging:
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$image= wp_get_attachment_image( $attachment->ID, 'thumbnail' , false, array( 'id' => $attachment->ID ));
echo $image;
print_r(wp_get_attachment_image_src( $attachment->ID, 'thumbnail' , false, array( 'id' => $attachment->ID )));
echo var_export($image);
echo '<p>' . $attachment->post_title . '</p>';
}
}
}
returns this:
Array ( [0] => http://localhost/multi/wp-content/uploads/2011/11/FabricColllFabrics-150x150.jpg [1] => 100 [2] => 100 [3] => 1 )
false
FabricColllFabrics
for the first image... so wp_get_attachment_image_src is correctly finding the source, but wp_get_attachment_image is apparently returning false?
edit 2: and there's the face palm i was waiting on
at some point i must've been debugging something and for who knows what reason i put a
function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {
return false;
right at the beginning of wp_get_attachment_image
this is all localhost stuff, and i don't usually hack at core, but i guess at some point i was in there probably trying to backtrace something and forgot to clean up after myself. epic fail.
wp_get_attachment_image( $attachment->ID )
?