0

Using:

$my_query->the_post();
$thumbnail_arr = wp_get_attachment_image_src(the_ID(), "medium");
$thumbnail = $thumbnail_arr[0];

$thumbnail is outputting a blank value.

If I echo the_ID() it is blank also.

Help appreciated.

EDIT

I've tried:

$my_query->the_post();
$thumbnail_arr = wp_get_attachment_image_src($my_query->post->ID, "medium");
$thumbnail = $thumbnail_arr[0];

but $thumbnail is still empty.

1
  • 1
    I know you already found a solution (to get the featured image ID/URL), but keep in mind that the_ID() displays the post ID, and returns nothing. So you should use get_the_ID() instead to get the post ID. That way, echo get_the_ID() would echo the correct post ID, when inside of The Loop.
    – Sally CJ
    Commented Sep 27, 2022 at 12:17

1 Answer 1

0

I changed to:

 $attch_id = get_post_thumbnail_id( $my_query->post->ID );
 $thumbnail_arr = wp_get_attachment_image_src($attch_id, "medium");
 $thumbnail = $thumbnail_arr[0];

and $thumbnail is returning what I want now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.