wp_get_attachment_thumb_url()
doesn’t accept three parameters. It takes one– the attachment ID. And, as you might guess from the name of the function, it return the thumbnail URL *_thumb_url
. If you’d have simply checked the Codex entry for the function you’d have seen that.
If you’d check the Codex, you’d see several other things too
-
Don’t use
query_posts()
Note: This function isn’t meant to be used by plugins or themes.
numberposts
has long since been deprecated. In fact, it may not
work at all anymore as I can’t find it mentioned in the Codex any
longer, nor do I see it the source forWP_Query
.
Let’s correct this. The key function you want is wp_get_attachment_image_src()
, but your code is an poorly formatted, unreadable mess. Let’s fix that too.
- Use a new
WP_Query
object instead ofquery_posts()
I don’t know
what arguments you are using as you didn’t post that part. - Use
posts_per_page
instead ofnumberposts
(which name never made
sense anyway) - Use
wp_get_attachment_image_src()
- Indent, and format, and organize. Save your sanity man!
Which gives us…
$args = array('post_type' => 'post'); // not sure what your actually are.
$images = new WP_Query($args);
if ($images->have_posts()) {
while ($images->have_posts()) {
$images->the_post();
$args = array(
'post_type' => 'attachment',
'posts_per_page' => 3,
'orderby' => 'rand',
'order' => 'DESC',
'post_mime_type' => 'image' ,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$image = wp_get_attachment_image_src( $attachment->ID,'large', false );
if (empty($image[0])) continue;
$image_meta = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); ?>
<a href="https://wordpress.stackexchange.com/questions/207756/<?php echo $image[0]; ?>" title="<?php the_title(); ?>">
<img src="https://wordpress.stackexchange.com/questions/207756/<?php echo $image[0]; ?>" alt="<?php echo $image_meta ?>" />
</a><?php
}
}
}
}
wp_reset_postdata();