Support

Account

Home Forums Front-end Issues Only display field group if specific option is selected in ACF select field?

Unread

Only display field group if specific option is selected in ACF select field?

  • Hi all,
    So I set up an ACF field called “region” in which the backend user can select the region for each sports league that they input (Southwest, North, SouthEast, etc.) “Region” is part of a field group with other fields with information such as the league’s address and contact information.

    Is there any way to display say, only the information from the field group in a certain div or list if a particular region is selected (i.e. Southwest)?

    In other words, I’m really trying to filter and organize the lists based on region. It also has to be part of the WordPress loop.

    I tried the following and it didn’t work (it’s obviously totally wrong, but it’s to show that I did try my best…):

    <li id="alaska">
    <h3>Northwest</h3>
    
    <table id="mytable2">
    	<tr>
      	<th>State</th> <th>Leagues</th>
      </tr>
      	<?php 
    
      $args = array(
        'post_type' => 'leagues',
        'post_status' => 'publish',
        'posts_per_page' => '3'
      );
      $tournaments_loop = new WP_Query( $args );
      if ( $tournaments_loop->have_posts() ) :
        while ( $tournaments_loop->have_posts() ) : $tournaments_loop->the_post();
          // Set variables
          $title = get_the_title();
          $state = get_field('league_state');
          $option = get_field("league_region");
    
    if($option=="southwest"){
      // display field;
    }else {
      // don't display 
    }
          
          // Output
          ?>
    
          
    <tr>
      	<tr>
      	<td><?php echo $state; ?></td> <td><?php echo $title; ?></td>
      </tr>
    
          <?php
          endwhile;
        wp_reset_postdata();
      endif; ?> 
    
      </table>
        </li>

    Thank you.

Viewing 1 post (of 1 total)

The topic ‘Only display field group if specific option is selected in ACF select field?’ is closed to new replies.