Dans le cadre d’un ACF, si vous voulez récupérer l’ID d’une image stocké dans un repeater en fonction de son URL, vous pouvez utiliser cette fonction en attendant la fonction officielle fonctionne sous WordPress 3.7 ( http://codex.wordpress.org/Function_Reference/url_to_postid )
//
function get_attachment_id_from_src($image_src) {
global $wpdb;
$query = "SELECT `ID` FROM `$wpdb->posts` WHERE `guid` = '".$image_src."'";
$id = $wpdb->get_var($query);
return $id;
}}
// En application
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()) : $the_query->the_post();
if(get_field('images')):
$indice = 1;
while(has_sub_field('images')):
$_url = get_sub_field('image');
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
$attachment_id = get_attachment_id_from_src($_url);
$image = wp_get_attachment_image_src($attachment_id, $size);
echo "<img src=\"".$image[0]."\" alt=\"Image #$indice\" />";
$indice++;
endwhile;
endif;
endwhile;
endif;
Réponse