Title: Conditional Statement (Advanced Custom Fields)
Last modified: August 22, 2016

---

# Conditional Statement (Advanced Custom Fields)

 *  Resolved [daisy-d](https://wordpress.org/support/users/daisy-d/)
 * (@daisy-d)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/conditional-statement-advanced-custom-fields-1/)
 * Hi,
 * I’m using the Advanced Custom Fields plugin with the Repeater add-on. ([http://www.advancedcustomfields.com](http://www.advancedcustomfields.com))
 * I have a repeater field called portfolio_images with two sub fields – image and
   portfolio_link.
 * Some images will be linked and others not so I only want the link to appear if
   the field has been completed otherwise I just want the image to show.
 * This is the code I am using at the moment:
 *     ```
       <?php if( have_rows('portfolio_images') ): ?>
       <?php while( have_rows('portfolio_images') ): the_row(); ?>
       <?php
            $portfolio_link = get_sub_field('portfolio_link');
            if ($portfolio_link == '') {
                 echo '<img src="' . the_sub_field('image') . '" /><br />';
            }
            else {
                 echo '<a href="' . the_sub_field('portfolio_link') . '"><img src="' . the_sub_field('image') . '" />' . '</a><br />';
            }
       ?>
       <?php endwhile; ?>
       <?php endif; ?>
       ```
   
 * It outputs all of the values but just not within the html i.e.
 *     ```
       http://www.bob.co.ukhttp://dd-dev.co.uk/bob/wp-content/uploads/2014/11/ifp-portfolio-1.png<a href=""><img src="" /></a>                                    
   
       http://dd-dev.co.uk/bob/wp-content/uploads/2014/11/ifp-portfolio-2.png<img src="" />
       ```
   
 * Can anyone help me at all?
 * Thanks

Viewing 1 replies (of 1 total)

 *  Thread Starter [daisy-d](https://wordpress.org/support/users/daisy-d/)
 * (@daisy-d)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/conditional-statement-advanced-custom-fields-1/#post-5878308)
 * Managed to find the solution so if anyone else comes across something similar
   this fixed it:
 *     ```
       <?php if( have_rows('portfolio_images') ): ?>
            <?php while( have_rows('portfolio_images') ): the_row(); 
   
                 $image = get_sub_field('image');
                 $link = get_sub_field('portfolio_link');
   
            ?>
            <?php if( $link ): ?>
                 <a href="<?php echo $link; ?>">
            <?php endif; ?>
   
            <img src="<?php echo $image; ?>" />
   
            <?php if( $link ): ?>
                 </a>
            <?php endif; ?>                                
   
            <?php endwhile; ?>
       <?php endif; ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Conditional Statement (Advanced Custom Fields)’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [daisy-d](https://wordpress.org/support/users/daisy-d/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/conditional-statement-advanced-custom-fields-1/#post-5878308)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
