I’m trying to hide all the html if my custom fields are empty in WordPress
I’m using this:
<?php if (the_field( 'attribute_1' ) & the_field( 'value_1' ) != "") { ?>
<li style="line-height:2.25em;border-top:1px solid #dcdcdc;"><p style="font-size:15px;margin-bottom:0;"><?php the_field( 'attribute_1' ); ?> <span style="float:right;font-weight:600;font-family:'Varela Round';"><?php the_field( 'value_1' ); ?></span></p></li>
<?php } ?>
But only 1 custom field shows up, any ideas why? I’ve looked into it quite a bit but can’t figure it out
assuming that your fields are correct (
attribute_1
andvalue_1
), then the issue with the code is the use of the incorrect functions.the_field outputs the contents of the field.
In your
if
condition, you need to use get_field which returns the contents of the field:Since you have not provided details about the methods listed above, you could try something like this.
If you are banking on ‘myfield’ being variables from a different page, then you should use: