Support

Account

Home Forums Front-end Issues Hide empty fields when using groups

Helping

Hide empty fields when using groups

  • Hi there,

    I am currently trying to hide a section of my template when one or more conditions (fields in this case) are not met or filled out. My section looks like this:

    <section class="werdegang">
    
            <?php
                $werdegang = get_field('werdegang'); // parent group
                $station1 = $werdegang['station_1']; // ' child group 1
                $station2 = $werdegang['station_2']; // 'child group 2
                $station3 = $werdegang['station_3']; // 'child group 3
             ?>
    
            <span class="werdegang-headline">Die wichtigsten Stationen meines Werdegangs.</span>
            <hr class="willkommen-divider"></hr>
    
            <div class="werdegang-container">
              <div class="timeline">
                <div class="timeline-nav">
                  <div class="timeline-nav__item"><?php echo $station1['jahr_station_1'];?></div>
                  <div class="timeline-nav__item"><?php echo $station2['jahr_station_2'];?></div>
                  <div class="timeline-nav__item"><?php echo $station3['jahr_station_3'];?></div>
                </div>
                <div class="timeline-wrapper">
                  <div class="timeline-slider">
                    <div class="timeline-slide" data-year="<?php echo $station1['jahr_station_1'];?>">
                      <div class="timeline-slide__content">
                        <h4 class="timeline-title"><?php echo $station1['titel_station_1'];?></h4>
                        <p class="timeline-text"><?php echo $station1['beschreibung_station_1'];?></p>
                      </div>
                    </div>
                    <div class="timeline-slide" data-year="<?php echo $station2['jahr_station_2'];?>">
                      <div class="timeline-slide__content">
                        <h4 class="timeline-title"><?php echo $station2['titel_station_2'];?></h4>
                        <p class="timeline-text"><?php echo $station2['beschreibung_station_2'];?></p>
                      </div>
                    </div>
                    <div class="timeline-slide"  data-year="<?php echo $station3['jahr_station_3'];?>">
                      <div class="timeline-slide__content">
                        <h4 class="timeline-title"><?php echo $station3['titel_station_3'];?></h4>
                        <p class="timeline-text"><?php echo $station3['beschreibung_station_3'];?></p>
                      </div>
                    </div>
    
                  </div>
                </div>
              </div>
            </div>
    
          </section>

    And what I already tried to do was to wrap this section into something like this:

    <?php
            if (the_field('werdegang', $term)) {
              ?>
    SECTION CONTENT
    <?php
            }
              ?>
    
    

    or this:

    <?php
            if (the_field('jahr_station_1', $term)) {
              ?>
    SECTION CONTENT
    
    <?php
           }
              ?>
    

    Or this:

    <?php if( get_field('werdegang') ): ?>
    	SECTION CONTENT
    <?php endif; ?>

    Or this:
    `<?php
    if( have_rows(‘werdegang’) ):
    ?>
    SECTION CONTENT
    <?php endif; ?>

    What it does do: Hide the section regardeless if it is filled out or not. But I want to hide it only when something is NOT filled out. Does anyone have any pointers for not displaying a section that way? I cant get it to work properly.

    Thanks!

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

The topic ‘Hide empty fields when using groups’ is closed to new replies.