Support

Account

Home Forums ACF PRO Repeater Values shown only if marked as TRUE

Solved

Repeater Values shown only if marked as TRUE

  • I’m using the following code successfully to show all of my degrees listed in a comma delimited list:

    <?php if( get_field('degrees') ) {
    	while ( have_rows('degrees') ) : the_row();
    	 $array[] = get_sub_field('degree_select'); 
    	endwhile;
    		$foo = implode(', ', array_column($array, 'label'));
    		echo '<span class"">, ' . $foo . '</span>';
    	}								
    ?>

    …however I want to be able to limit which ones I show in my comma delimited list by using a True/False checkbox. Here is what the backend looks like:

    backend

    You’ll see that ONLY 2 have been checked to display.

    This True/False value has the name of: degree_aftername

    How can I modify my code, to only implode the ones that have been marked as TRUE?

  • 
    <?php if( get_field('degrees') ) {
    	while ( have_rows('degrees') ) : the_row();
              if (!get_sub_field('degree_aftername')) {
                continue;
              }
    	 $array[] = get_sub_field('degree_select'); 
    	endwhile;
    		$foo = implode(', ', array_column($array, 'label'));
    		echo '<span class"">, ' . $foo . '</span>';
    	}								
    ?>
    
  • Thanks John! Worked perfectly!

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

The topic ‘Repeater Values shown only if marked as TRUE’ is closed to new replies.