Support

Account

Forum Replies Created

  • I got to it in the end….

    Here’s my working solution:

    <?php 
    $all_attributes = array();
    $filter_attributes = array();
    
    if (have_rows('logos')): while (have_rows('logos')) : the_row(); 
        $attributes = get_sub_field_object('partner'); 
        $values[] = get_sub_field('partner'); 
        if($values) {
            foreach ($values as $value) 
                $all_attributes[] = $value; /* Save ALL values */
        } 
     endwhile; endif;
    
    /* use array_unique to remove duplicates from the array */
    $filter_attributes = array_unique ($all_attributes);
    ?>
    
    <?php $colors = $filter_attributes;
    	foreach ($colors as $color) {
    	    global $b;
    		$b++;
    		echo "<h3>" . ucfirst($color) . "</h3>";
    		echo '<div class="row">';
    		while ( have_rows('logos') ) : the_row();
    		    if(get_sub_field('partner') == "{$color}"):
    				// display the repeater sub field values
    				echo    '<div class="col-sm-6 col-md-3 text-center py-3" id="'.$b.'">
    						 <a href="' . get_sub_field('website') .'"><img src="' .get_sub_field('logo') . '" /></a>
    					     </div>';
    			endif;
    		endwhile;
    	echo '</div>'; 
    }?>
  • Okay I’ve refined it a heap after looking into arrays:

    <?php if( have_rows('logos') ):
    
    	while( have_rows('logos') ): the_row(); 
    
    		$select = get_sub_field_object('partner');
    		$value = get_sub_field('partner');
    		$partnerArray = $select['choices']; 
    
    	endwhile;
    
     endif; ?>
    		
    <?php $colors = $partnerArray;
    	foreach ($colors as $color) {
    	    global $b;
    		$b++;
    			
    		echo "<h3>" . ucfirst($color) . "</h3>";
    		echo '<div class="row">';
    		while ( have_rows('logos') ) : the_row();
    		    if(get_sub_field('partner') == "{$color}"):
    				// display the repeater sub field values
    				echo    '<div class="col-sm-6 col-md-3 text-center py-3" id="'.$b.'">
    						 <a href="' . get_sub_field('website') .'"><img src="' .get_sub_field('logo') . '" /></a>
    					     </div>';
    			endif;
    		endwhile;
    	echo '</div>'; 
    }?>

    However it will display the titles regardless. If the titles exist, they are shown, even if there are no items on that page. I need them to only show if there are items.

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