Support

Account

Home Forums General Issues Repeater php break problem

Helping

Repeater php break problem

  • Good day,

    I have a problem with using a break in a repeater field have_rows() loop.
    When i use it the next repeater under need it doesn’t pass the if stament.

    In the code u see the first repeater called “fights_fightcards” this needs a break so it stop looping after hitting the correct amount of results.

    Under need that repeater you find the repeater called “buttons_fight_type_fightcards”. This repeater doesn’t work if I use a break in the other one. when I use a continue it while go thru and and show the button and it divs.

    This is the code when it works.

    
    							<?php if(have_rows($fight_type_fightcards)){ //Check if reapter exist?>
    
    								<?php $count_fight_type = 0; //Make a count variable foreach row in the repeater?>
    								
    								<?php while(have_rows($fight_type_fightcards)){ the_row(); //Go thru every result in the repeater?>
    
    									<?php $fights_fightcards = 'fights_fightcards'; // Create variable voor repeater inside other repeater?>
    									<?php $buttons_fight_type_fightcards = 'buttons_fight_type_fightcards';// Create variable voor repeater inside other repeater?>
    									<?php if($count_fight_type === 0){ //set active class on first repeater by count?>
    										<?php $class="col-group fights-container active"; ?>
    									<?php }else{ ?>
    										<?php $class="col-group fights-container"; ?>
    									<?php } ?>
    
    									<div class="<?php echo $class;?>" data-fight-container='<?php echo $count_fight_type;?>'>
    
    										<div class="col fightcards-container">
    											<?php
    												$number = 3;//Number of fields shown
    												$count_fight_cards = 0;//Count variable foreach resulte in next array 
    												$total = count(get_sub_field($fights_fightcards))//Count all results from repeater;
    											?>
    											<?php if(have_rows($fights_fightcards)){
    												while(have_rows($fights_fightcards)){ the_row();
    													if ($count_fight_cards == $number) {
    														continue;
    													}else{
    														include(get_stylesheet_directory().'/parts/fightcard-2.php');
    														$count_fight_cards++; 
    													}
    												}
    											} ?>
    										</div>
    
    										<?php if($total > $count_fight_cards){ ?>
    											<div class="col load-more">
    
    												<p class="load-more-button-fightcard" 	
    													data-row_index="<?php echo $row_index;?>"
    													data-count_fight_type="<?php echo $count_fight_type;?>"
    													data-offset="<?php echo $number;?>"
    													data-post-id="<?php echo get_the_ID();?>"
    													>Show Full Card
    
    											</div>
    										<?php } ?>
    										<?php $total > $count_fight_cards ? $class='col buttons': $class="col buttons active";?>
    										<?php if(have_rows($buttons_fight_type_fightcards)){ ?>
    											<div class="<?php echo $class;?>">
    												<?php while(have_rows($buttons_fight_type_fightcards)){ the_row();?>
    													<?php $button = get_sub_field('button');?>
    													<?php if($button){ ?>
    														<?php if($button['url'] && $button['title']){ ?>
    															<?php if($button['target']){ ?>
    																<?php $target = '_blank';?>
    															<?php }else{?>
    																<?php $target = '_self';?>
    															<?php } ?>
    															<div class="button">
    																<a href="<?php echo $button['url'];?>" target="<?php echo $target;?>">
    																	<?php echo $button['title'];?>
    																</a>
    															</div>
    														<?php } ?>
    													<?php } ?>
    												<?php } ?>
    											</div>
    										<?php } ?>
    									</div>
    								<?php $count_fight_type++; } ?>
    							<?php } ?>
    

    I hope someone can help me with this problem.

  • Try calling reset_rows() just before the break

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

You must be logged in to reply to this topic.