I'm using Wordpress and the advanced custom fields plugin to create gallery thumbnails. There are 9 possible upload fields, but only the first is required.
At present I am having an issue where any of the fields are empty it is still outputting the img tag but showing a corrupt image (as there is no image).
I need to create an if statement that only outputs the HTML if the field has a src (or if the field isn't empty).
This is my current code, there are 9 of these:
<li>
<div class="portfolioPicker">
<?php $image = wp_get_attachment_image_src(get_field('portfolio_image_2'), 'thumbnail'); ?>
<img id="portfolioImg_2" class="portfolioPickerThumb" src="<?php echo $image[0]; ?>" alt="<?php echo get_the_title(get_field('portfolio_image_2')) ?>" />
</div>
</li>
I have found a good piece of code for the PHP if statement but am struggling to get it working with my current output code:
<?php if( get_post_meta($post->ID, "mycustomfieldname", true) ): ?>
<?php echo get_post_meta($post->ID, "mycustomfieldname", $single = true);?>
<?php else: ?>
<?php endif; ?>