RappY
RappY

Reputation: 472

Wordpress get thumbnail

I have a problem. I need to get the thumbnail of my picture. I have this addon called custom fields where i can add fields to a post, fill them out and get them out with the_field('picture1', $page->ID); in my php code.

I have several of those fields etc. picture2, picture 3 and so on.

But i need to get the thumbnail of the picture. I can either get an output with the image object, the id of the picture or the url of the picture.

How do i get the url of the thumbnail? I've been trying things like

$thumb = wp_get_attachment_image_src(get_field('picture1', $page->ID), 'thumbnail');

But all i get is a empty output. What can i do?

Upvotes: 0

Views: 104

Answers (2)

TeeDeJee
TeeDeJee

Reputation: 3741

$thumb = wp_get_attachment_image_src(get_field('picture1', $page->ID), 'thumbnail');

If you read the codex for wp_get_attachment_image_src, you can see that it returns an array.

Return Value

An array containing:
0 => url,
1 => width,
2 => height,
3 => boolean: true if $url is a resized image, false if it is the original or if no image is available.

So for the url you would need to get the first item of the array $thumb[0].

Upvotes: 1

RappY
RappY

Reputation: 472

Solved it by using

$image_1 = wp_get_attachment_image_src(get_field('image1', $page->ID), 'thumbnail');
echo $image_1[0];

Upvotes: 0

Related Questions