Support

Account

Home Forums Add-ons Repeater Field loop to display all subfield of a repeater Reply To: loop to display all subfield of a repeater

  • If you don’t already know the names (or field keys) of the sub fields then that’s going to be an issue. You have to get these, this might work, but no promises as I have not tested it.

    
    if( have_rows('gerants', 'option') ):
       while ( have_rows('gerants', 'option') ) : the_row(); 
    	 
    	   // get the sub field object of the nested repeater
    		 // and store a list of sub fields
    	 	 $reseaux_sociaux = get_sub_field_object('reseaux-sociaux');
    		 $fields = array();
    		 if (count($reseaux_sociaux['sub_fields'])) {
    			 foreach ($reseaux_sociaux['sub_fields'] as $field) {
    					$fields[] = $field['name']; 
    			 }
    		 }
         if( have_rows('reseaux-sociaux', 'option') ):
           while ( have_rows('reseaux-sociaux', 'option') ) : the_row(); 
    		   	 echo '<ul>';
    					foreach ($fields as $sub_field) {	
    						$field = get_sub_field_object($sub_field);
    						echo '<li>' . $field['label'] . ': '.$field['value'].'</li>';			
    					}
    				echo '</ul>';
           endwhile;
         endif;
       endwhile;
    endif;