web-dev-qa-db-fra.com

Comment récupérer l'attribut alt d'une pièce jointe (image téléchargée)?

J'ai quelques identifiants de pièces jointes (images, pas de post en cours). Comment puis-je obtenir l'attribut alt pour ces images?

J'ai essayé d'examiner wp_get_attachment_image_src et wp_get_attachment_metadata mais je n'ai pas trouvé l'attribut alt stocké dans aucun de ceux-ci.

c'est là que je cherche l'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;   
1
unfulvio

Je n'ai pas réellement testé cela, mais j'ai rencontré le code suivant lors de mes voyages. Cela pourrait-il aider?

get_post_meta($attachment_id, '_wp_attachment_image_alt', true)

4
dunc