Check if any of the fields contain values, if yes wrap them in tag
-
Not a support request for the plugin author(s) but a kind of *Hi, I have this issue (minor) and I’m curious if any of the forum members have an idea how to go about solving it*
That said, here goes : )
I’ve set up a field group with four text fields (localhost so there’s no link). None of the fields are required, the post author may fill out all four or none or somewhere in between, and I’m showing them only if they contain value, like so:
<!-- These are the custom fields, One/two/three/four --> <p> <?php if(get_field('field_one’)) { echo '<strong>Field one</strong>: ', get_field(‘field_one) ; } ?><br /> <?php if(get_field('field_two’)) { echo '<strong>Field two</strong>: ', get_field('field_two’) ; } ?><br /> <?php if(get_field('field_three’)) { echo '<strong>Field three</strong>: ', get_field('field_three’) ; } ?><br /> <?php if(get_field('field_four’)) { echo '<strong>Field four</strong>: ', get_field('field_four’) ; } ?><br /> </p> <!-- End of the custom fields -->
Before the field values I show a
<strong>Field one</strong>
and seperate them with a<br />
tag, but I need to wrap the output (fields with values) in a<p>
tag in order to behave well within the theme.As it is the openeing and closing
<p></p>
tags are there regardless, which creates an ugly space when none of the fields are populated.What I would like to do is to check if any of the fields contain values and then (and only then) insert the
<p>
tag before the first one, and a closing</p>
after the last one.Any ideas would be much appreciated.
Thhttps://www.ads-software.com/plugins/advanced-custom-fields/
- The topic ‘Check if any of the fields contain values, if yes wrap them in tag’ is closed to new replies.