Support

Account

Home Forums Front-end Issues Hide container of Group Field from page if no one field have value

Helping

Hide container of Group Field from page if no one field have value

  • Hello!
    Please tell me how can I hide a container of a group of fields if the value is empty?

    <?php
    
        $icons = get_field('icons-group');  
    
        if( $icons ): ?>
        <div class="icons-group">
            <h3><?php the_title(); ?></h3>
            <div class="icons">
                <?php if ( $icons['icon-1'] ): ?><span class="icon-item"><?php echo $icons['icon-1']; ?></span><?php endif; ?>
                <?php if ( $icons['icon-2'] ): ?><span class="icon-item"><?php echo $icons['icon-2']; ?></span><?php endif; ?>
                <?php if ( $icons['icon-3'] ): ?><span class="icon-item"><?php echo $icons['icon-3']; ?></span><?php endif; ?>
                <?php if ( $icons['icon-4'] ): ?><span class="icon-item"><?php echo $icons['icon-4']; ?></span><?php endif; ?>
                <?php if ( $icons['icon-5'] ): ?><span class="icon-item"><?php echo $icons['icon-5']; ?></span><?php endif; ?>
                <?php if ( $icons['icon-6'] ): ?><span class="icon-item"><?php echo $icons['icon-6']; ?></span><?php endif; ?>
            </div>
        </div>
    
    <?php endif; ?>

    icon-1(2, ect) — True\False fields. I need hide the <div class="icons-group"> from page if no one fields is checked.

    I tried many options before asking a question.
    Thanks for help!

  • 
    $icons = get_field('icons-group');
    $filtered = array_filter($icons);
    if ($filtered) {
      // at least one of $icons has a value
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.