I have some IDs of attachments (images, not from current post). How to I get the alt attribute for those images?
I have tried to look into wp_get_attachment_image_src and wp_get_attachment_metadata but couldn’t find the alt attribute stored in neither of those
this is where I’m looking for the alt:
while(the_repeater_field('featured_pics')): //this is an array of IDs
$image_id = get_sub_field('featured_pic'); // this function gets an individual ID from array
$image_attr = wp_get_attachment_image_src(get_sub_field('featured_pic'), 'medium');
echo '<li class="showcase-pic"><a href="'.$image_attr[0].'" rel="lightbox">'.wp_get_attachment_image($image_id, 'thumbnail').'</a></li>';
endwhile;
I haven’t actually tested this, but came across the following code on my travels. Might this help?
get_post_meta($attachment_id, '_wp_attachment_image_alt', true)