Home Forums General Issues Hiding Empty/Unhiding non-empty Fields not working


Hiding Empty/Unhiding non-empty Fields not working

  • Hello. Great plugin that is almost working perfectly. I’ll submit each problem as a separate topic.

    The following example doesn’t work. It’s supposed to display the label and the form value if there is a value:

    <?php if( get_field('field_name') ): ?>
    	<p>My field value: <?php the_field('field_name'); ?></p>
    	<?php endif; ?>

    This code was taken from your documentation page:

    When I use the above code, nothing appears even though there is value in the field I’ve specified in the code. Is there any other code that I can use that will get this to work?

  • Hi @jimario

    Can you please debug the data like so:

    <?php echo '<pre>';
    	print_r( get_field('field_name') );
    echo '</pre>';
    die; ?>

    You may see that there is no data loaded. If so, please confirm where you are loading the data from. A post? A user, etc.

  • I placed the above code in a template file and it broke the template. The data is coming from a field added to a user’s profile. While editing the profile on user-edit.php, I can see that the data has successfully saved.

    The problem is that the hide/unhide code referenced in my original post doesn’t really pull and unhide the data and its label.

    <?php if( get_field('street_address_address') ): ?>
    	<p>My real address:  <?php the_field('street_address_address'); ?></p>
    	<?php endif; ?>

    The code above shows how I’ve coded my template. If it were to work, it should say:
    My real address: 4027 e. kyle

    But instead nothing shows. Here is the actual page:

    The label and data should show up under the photo/ID #.

  • Would it be easier for you to solve if I gave you ftp and admin acecess?

  • Hi @jimario

    If you are loading data from a user’s profile, you will need to correctly follow the steps in this tutorial:


  • I finally got it to work:

    This is the code I’m using:

    <?php if( get_the_author_meta('street_address_address', $curauth->ID) != '') :?>
    <dt><div class="thelabels"></div>Street Address:  <?php echo $curauth->street_address_address; ?></dt>
    <?php endif;?>
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Hiding Empty/Unhiding non-empty Fields not working’ is closed to new replies.