Support

Account

Home Forums General Issues hiding fields…

Solved

hiding fields…

  • Hello!

    I’m trying to hide the custom fields if they’re empty. I looked up this article: http://www.advancedcustomfields.com/resources/hiding-empty-fields/, but I am still a bit confused.

    The problem is that the HTML coding makes it a bit difficult for me to insert the PHP codes to hide them. Here is the HTML code I am referring to:

    <div class="currents">
    	<div class="currentmood">
    		<strong>Current Mood:</strong>
    		<img alt="" src="" />
    	</div> <!-- .currentmood -->
    	<div class="currentmusic">
    		<strong>Current Music:</strong> Music here
    	</div> <!-- .currentmusic -->
    </div> <!-- .currents -->

    My goal is to hide an empty field, but still show the other field along with the DIV “currents”. But if both fields are empty, I want to hide the DIV “currents” altogether.

    This is what I have so far:

    <div class="currents">
    	<?php if( get_field('current_mood') ): ?>
    	<div class="currentmood">
    		<strong>Current Mood:</strong> <?php the_field('current_mood'); ?>
    	</div> <!-- .currentmood -->
    	<?php endif; ?>
    	<?php if( get_field('current_music') ): ?>
    	<div class="currentmusic">
    		<strong>Current Music:</strong> <?php the_field('current_music'); ?>
    	</div> <!-- .currentmusic -->
    	<?php endif; ?>
    </div> <!-- .currents -->

    I would very much appreciate the help.

  • never mind, fixed it!

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

You must be logged in to reply to this topic.