Support

Account

Home Forums Add-ons Gallery Field Random Gallery Image with wp_get_attachment_image() Reply To: Random Gallery Image with wp_get_attachment_image()

  • What about using it inside a foreach loop? This doesn’t work:

    $images = get_field('slides', false); 
    $size = 'full';
    $rand = array_rand($images, 1);
    
    foreach( $images as $image_id ) :
    wp_get_attachment_image( $image_id[$rand], $size, false, array('loading' => 'auto'));
    endforeach;