Support

Account

Home Forums Front-end Issues Hide Empty Fields on Posts

Solving

Hide Empty Fields on Posts

  • Hi There, I have been reading on how to hide empty fields on posts, but I can’t quite get it. I am new to php, so please bare with me. I tried to use the code on the page at: https://www.advancedcustomfields.com/resources/hiding-empty-fields/
    but got an error. Adding the code into the page.php file would not render the page.

  • Hello, Please Post your code here. I will check and give the solution.

  • Hi There, I have the ACF in the footer of my WordPress application:

    <!– footer –>
    <footer class=”footer” role=”contentinfo”>

    </footer>
    <!– /footer –>

    </div>
    <!– /wrapper –>
    <b>Amenities</b>
    <br>

    <!– Begin Custom Fields –>

    <?php if ( get_field(‘kitchen’ ) ) : ?>
    *<?php the_field(‘kitchen’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘air_conditioning’ ) ) : ?>
    *<?php the_field(‘air_conditioning’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘dishwasher’ ) ) : ?>
    *<?php the_field(‘dishwasher’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘microwave’ ) ) : ?>
    *<?php the_field(‘microwave’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘washer_dryer’ ) ) : ?>
    *<?php the_field(‘washer_dryer’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘screened_porch’ ) ) : ?>
    *<?php the_field(‘screened_porch’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘bed_linens_provided’ ) ) : ?>
    *<?php the_field(‘bed_linens_provided’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘fireplace’ ) ) : ?>
    *<?php the_field(‘fireplace’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘pool_table’ ) ) : ?>
    *<?php the_field(‘pool_table’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘high_speed_internet’ ) ) : ?>
    *<?php the_field(‘high_speed_internet’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘cable_tv’ ) ) : ?>
    *<?php the_field(‘cable_tv’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘dvdvcr’ ) ) : ?>
    *<?php the_field(‘dvdvcr’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘private_pool’ ) ) : ?>
    *<?php the_field(‘private_pool’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘heated_pool’ ) ) : ?>
    *<?php the_field(‘heated_pool’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘hot_tub’ ) ) : ?>
    *<?php the_field(‘hot_tub’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘grill’ ) ) : ?>
    *<?php the_field(‘grill’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘enclosed_outside_shower’ ) ) : ?>
    *<?php the_field(‘enclosed_outside_shower’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘game_room’ ) ) : ?>
    *<?php the_field(‘game_room’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘elevator’ ) ) : ?>
    *<?php the_field(‘elevator’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘pets_allowed’ ) ) : ?>
    *<?php the_field(‘pets_allowed’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘non_smoking’ ) ) : ?>
    *<?php the_field(‘non_smoking’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘community_facilities’ ) ) : ?>
    *<?php the_field(‘community_facilities’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘community_pool’ ) ) : ?>
    *<?php the_field(‘community_pool’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘community_tennis_courts’ ) ) : ?>
    *<?php the_field(‘community_tennis_courts’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘community_club_house’ ) ) : ?>
    *<?php the_field(‘community_club_house’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘golf’ ) ) : ?>
    *<?php the_field(‘golf’); ?>
    <?php endif; ?>

    <?php if ( get_field(‘handicap_friendly’ ) ) : ?>
    *<?php the_field(‘handicap_friendly’); ?>
    <?php endif; ?>

    <!– /End Custom Fields –>

    <?php wp_footer(); ?>

    <br>
    <br>

    </body>
    </html>
    —————-

    It lays out o.k. but I would rather see it in 3 columns. I was able to set it up using a table at one point, but that really did not work at all as the empty cells in the table made gaps. I can set that up again though, maybe it would be better to show it that way. Let me know. Thanks so much. -Beth

  • The layout is a matter for CSS. It looks like this is supposed to be a list of some kind, so mark it up as such with HTML:

    
    <!– Begin Custom Fields –>
    <ul class="amenities">
    <?php if ( get_field(‘kitchen’ ) ) : ?>
    <li><?php the_field(‘kitchen’); ?></li>
    <?php endif; ?>
    <?php if ( get_field(‘air_conditioning’ ) ) : ?>
    <li><?php the_field(‘air_conditioning’); ?></li>
    <?php endif; ?>
    <?php if ( get_field(‘dishwasher’ ) ) : ?>
    <li><?php the_field(‘dishwasher’); ?></li>
    <?php endif; ?>
    …
    …
    <?php if ( get_field(‘handicap_friendly’ ) ) : ?>
    <li><?php the_field(‘handicap_friendly’); ?></li>
    <?php endif; ?>
    </ul>
    <!– /End Custom Fields –>
    

    … and then use CSS to lay it out the way you like. For a list displayed in multiple columns you can use the columns CSS module.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.