show custom field image based on another Custom Field?

I have created a website for a car sales company and used Custom Fields. I have set a main (required) image and also another 9 for additional images.

This all works fine except that when all aren’t used, it takes images from the next vehicle listing.

Read More

What I want it to do is to only show images based on each specific listing by using another custom field called 'ref' as these are different for each vehicle. (e.g., HLM001, HLM002)

The code for each image is:

<div class="col-md-4">
<?php $image = get_field('vehicle_image2'); if( !empty($image) ): ?>
<a href="<?php echo $image['url']; ?>" rel="lightbox"</a><img class="img-responsive thumbs" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>

This can be seen at http://hleemotors.co.uk/vans/ when clicking 'View more details'.

I’m ok with PHP but this has really stumped me. Any help would be great.

Related posts