Only display ACF fields if they have a value (are not empty)

Hi,

I am working on displaying some ACF fields in a acf_relationship loop and only want to display the field if they have any value in them, meaning as long as they are not empty. In this example I have one text field and one file field. How can those only be displayed if they are not empty?

<div class=workshop-details>
<Loop acf_relationship=related_workshops orderby=date order=desc>
  <h4><Field title /></h4>
  <span><Field presenter /></span> <br />
  <a href="{Field acf_file=slides field=url}">Download the slides</a>
  <p><Field content /></p>  
</Loop>
</div>

Thanks!

And I found it as soon as I posted this. It’s from this documentation page.

This code sample works

<div class=workshop-details>
<Loop acf_relationship=related_workshops orderby=date order=desc>
  <h4><Field title /></h4>
  <If field="presenter" exists><span><Field presenter /></span> <br /></If>
  <If field="slides" exists><a href="{Field acf_file=slides field=url}">Download the slides</a></If>
  <p><Field content /></p>  
</Loop>
</div>
2 Likes