Support

Account

Home Forums ACF PRO Repeater Field looping the last results

Solved

Repeater Field looping the last results

  • Hey, I am using ACF to generate tables for products on my website. I’m having some issues with the last repeater field showing on the front end, and it looping the amount of repeaters. It just seems to be causing the issue today though and I am not sure what the issue is. It was working fine yesterday.

    Here is the code causing the issues. It first checks if the fields exist, then saves them as a variable. Then it creates a <thead> based on the field types for the post, and then loops through each one as a <tr> :

    <!-- model specifications -->
    									<?php if( have_rows('model_specifications') ):
    									
    										while( have_rows('model_specifications') ): the_row();
     											$ms_model = get_sub_field('model');
     											$ms_gpm = get_sub_field('gpm');
     											$ms_input = get_sub_field('input');
     											$ms_psi = get_sub_field('psi');
     											$ms_drive = get_sub_field('drive');
     											$ms_rpm = get_sub_field('rpm');
     											$ms_drive_rpm = get_sub_field('drive_rpm');
     											$ms_hp = get_sub_field('hp');
     											$ms_volt = get_sub_field('volt');
     											$ms_hp_volt = get_sub_field('hp_volt');
     											$ms_power = get_sub_field('power');
     											$ms_engine = get_sub_field('engine');
     											$ms_burner = get_sub_field('burner');
     											$ms_electric_start = get_sub_field('electric_start');
     											$ms_size = get_sub_field('size');
    
     										endwhile;
    
    										
     											echo '<div id="model-specifications">';
    											echo '<table class="rwd-table">';
    											echo '<thead>';
    											echo '<tr>';
     											if ($ms_model) {echo '<th>Model</th>';}
     											if ($ms_gpm) {echo '<th>GPM</th>';}  
     											if ($ms_input) {echo '<th>Input</th>';}  
     											if ($ms_psi) {echo '<th>PSI</th>';} 
     											if ($ms_drive) {echo '<th>Drive</th>';} 
     											if ($ms_rpm) {echo '<th>RPM</th>';}
     											if ($ms_drive_rpm) {echo '<th>Drive RPM</th>';} 
     											if ($ms_hp) {echo '<th>HP</th>';} 
     											if ($ms_volt) {echo '<th>Volt</th>';}
     											if ($ms_hp_volt) {echo '<th>HP / Volt</th>';}
     											if ($ms_power) {echo '<th>Power</th>';}
     											if ($ms_engine) {echo '<th>Engine</th>';} 
     											if ($ms_burner) {echo '<th>Burner</th>';} 
     											if ($ms_electric_start) {echo '<th>Electric Start</th>';}
     											if ($ms_size) {echo '<th>Size</th>';}
     											echo '<th>Quote</th>';
     											echo '</tr>';
     											echo '</thead>';
     											
     											echo '<tbody>';
     											while( have_rows('model_specifications') ): the_row();
     											echo '<tr>';
     											if ($ms_model) {echo '<td data-th="Model">'.$ms_model.'</td>';}
     											if ($ms_gpm) {echo '<td data-th="GPM">'.$ms_gpm.'</td>';}  
     											if ($ms_input) {echo '<td data-th="Input">'.$ms_input.'</td>';}  
     											if ($ms_psi) {echo '<td data-th="PSI">'.$ms_psi.'</td>';} 
     											if ($ms_drive) {echo '<td data-th="Drive">'.$ms_drive.'</td>';} 
     											if ($ms_rpm) {echo '<td data-th="RPM">'.$ms_rpm.'</td>';} 
     											if ($ms_drive_rpm) {echo '<td data-th="Drive RPM">'.$ms_drive_rpm.'</td>';}
     											if ($ms_hp) {echo '<td data-th="HP">'.$ms_hp.'</td>';} 
     											if ($ms_volt) {echo '<td data-th="Volt">'.$ms_volt.'</td>';} 
     											if ($ms_hp_volt) {echo '<td data-th="HP / Volt">'.$ms_hp_volt.'</td>';}
     											if ($ms_power) {echo '<td data-th="Power">'.$ms_power.'</td>';}
     											if ($ms_engine) {echo '<td data-th="Engine">'.$ms_engine.'</td>';} 
     											if ($ms_burner) {echo '<td data-th="Burner">'.$ms_burner.'</td>';} 
     											if ($ms_electric_start) {echo '<td data-th="Electric Start">'.$ms_electric_start.'</td>';}
     											if ($ms_size) {echo '<td data-th="Size">'.$ms_size.'</td>';}
    											echo '<td data-th="Quote"><a href="/request-a-quote/?">Request a Quote</a></td>';
    											echo '</tr>';
    											endwhile;
    											echo '</tbody>';
     											echo '</table>';
     											echo '</div>';
     											
    									?>		
    									<?php endif; ?>									
        								<!-- end model specifications -->

    Any help would be appreciated.

  • hi
    try if it works when you remove the while loop inside tbody

  • Unfortunately not. This causes only one result to show now.

  • ok. i know the problem. could you try if this works for you

    <!-- model specifications -->
    									<?php if( have_rows('model_specifications') ):
    									$firstrow = "1";
    										while( have_rows('model_specifications') ): the_row();
     											$ms_model = get_sub_field('model');
     											$ms_gpm = get_sub_field('gpm');
     											$ms_input = get_sub_field('input');
     											$ms_psi = get_sub_field('psi');
     											$ms_drive = get_sub_field('drive');
     											$ms_rpm = get_sub_field('rpm');
     											$ms_drive_rpm = get_sub_field('drive_rpm');
     											$ms_hp = get_sub_field('hp');
     											$ms_volt = get_sub_field('volt');
     											$ms_hp_volt = get_sub_field('hp_volt');
     											$ms_power = get_sub_field('power');
     											$ms_engine = get_sub_field('engine');
     											$ms_burner = get_sub_field('burner');
     											$ms_electric_start = get_sub_field('electric_start');
     											$ms_size = get_sub_field('size');
    
     										if($firstrow == "1") :
    
    										
     											echo '<div id="model-specifications">';
    											echo '<table class="rwd-table">';
    											echo '<thead>';
    											echo '<tr>';
     											if ($ms_model) {echo '<th>Model</th>';}
     											if ($ms_gpm) {echo '<th>GPM</th>';}  
     											if ($ms_input) {echo '<th>Input</th>';}  
     											if ($ms_psi) {echo '<th>PSI</th>';} 
     											if ($ms_drive) {echo '<th>Drive</th>';} 
     											if ($ms_rpm) {echo '<th>RPM</th>';}
     											if ($ms_drive_rpm) {echo '<th>Drive RPM</th>';} 
     											if ($ms_hp) {echo '<th>HP</th>';} 
     											if ($ms_volt) {echo '<th>Volt</th>';}
     											if ($ms_hp_volt) {echo '<th>HP / Volt</th>';}
     											if ($ms_power) {echo '<th>Power</th>';}
     											if ($ms_engine) {echo '<th>Engine</th>';} 
     											if ($ms_burner) {echo '<th>Burner</th>';} 
     											if ($ms_electric_start) {echo '<th>Electric Start</th>';}
     											if ($ms_size) {echo '<th>Size</th>';}
     											echo '<th>Quote</th>';
     											echo '</tr>';
     											echo '</thead>';
     											
     											echo '<tbody>';
     										endif;
     										$firstrow++;
     											
     											echo '<tr>';
     											if ($ms_model) {echo '<td data-th="Model">'.$ms_model.'</td>';}
     											if ($ms_gpm) {echo '<td data-th="GPM">'.$ms_gpm.'</td>';}  
     											if ($ms_input) {echo '<td data-th="Input">'.$ms_input.'</td>';}  
     											if ($ms_psi) {echo '<td data-th="PSI">'.$ms_psi.'</td>';} 
     											if ($ms_drive) {echo '<td data-th="Drive">'.$ms_drive.'</td>';} 
     											if ($ms_rpm) {echo '<td data-th="RPM">'.$ms_rpm.'</td>';} 
     											if ($ms_drive_rpm) {echo '<td data-th="Drive RPM">'.$ms_drive_rpm.'</td>';}
     											if ($ms_hp) {echo '<td data-th="HP">'.$ms_hp.'</td>';} 
     											if ($ms_volt) {echo '<td data-th="Volt">'.$ms_volt.'</td>';} 
     											if ($ms_hp_volt) {echo '<td data-th="HP / Volt">'.$ms_hp_volt.'</td>';}
     											if ($ms_power) {echo '<td data-th="Power">'.$ms_power.'</td>';}
     											if ($ms_engine) {echo '<td data-th="Engine">'.$ms_engine.'</td>';} 
     											if ($ms_burner) {echo '<td data-th="Burner">'.$ms_burner.'</td>';} 
     											if ($ms_electric_start) {echo '<td data-th="Electric Start">'.$ms_electric_start.'</td>';}
     											if ($ms_size) {echo '<td data-th="Size">'.$ms_size.'</td>';}
    											echo '<td data-th="Quote"><a href="/request-a-quote/?">Request a Quote</a></td>';
    											echo '</tr>';
    											endwhile;
    											echo '</tbody>';
     											echo '</table>';
     											echo '</div>';
     											
    									?>		
    									<?php endif; ?>									
        								<!-- end model specifications -->
  • Thanks, that worked great! Really appreciate it man.

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

The topic ‘Repeater Field looping the last results’ is closed to new replies.