php - ACF - Repeater shows only last entered row, not all rows from post -


i have code inside functions.php file:

while ( have_rows('origin-repiter') ): the_row(); $origin = get_sub_field('origin-rep'); endwhile;   while ( have_rows('destination-repiter') ): the_row(); $destination =  get_sub_field('destination-rep'); endwhile; 

here origin-repiter/destination repiter repeater field name , origin-rep/destination-rep repeater fields, rows if want.

my problem on frontend of wp site acf shows last input backend repeater fields.

example:

for origin entered:

london, paris, moscow (three rows) same destination inverse (moscow, paris, london).

but on frontend acf showing last entry

origin: moscow & destination: london

this code functions.php renders php/html on frontend 2 fields/snippets:

$output .= '<div class="post_offer"><div class="offer-header"><div class="offer-pr"><div class="offer-pr-t"> from</div> <div class="offer-pr-v"><div class=""><div class="offer-pr-c">'.$fcurrency_icon .'</div><span class="price" style="font-size:30px;">'.$fprice.'</span></div></div></div> <h2 class="offer-tl editor-paragraph-tags">'.$ftitle.'</h2></div><div class="offer-rt-rd"><div class="offer-rt-rd-o"><div class="offer-rt-rd-lb">origin</div><div class="offer-rt-rd-lo">'.$origin.'</div></div><div class="offer-rt-rd-d"><div class="offer-rt-rd-lb">destination</div><div class="offer-rt-rd-lo">'.$destination .'</div></div><div class="offer-rt-rd-ico"></div></div>'; 

any appreciated!!!

addendum - whole code:

function add_box_post_end($content){ global $post; $postid = $post->id; $title = get_field('title_text', $postid); $ftitle = ($title != '')? $title :''; $currency_icon = get_field('currency_icon', $postid); $fcurrency_icon = ($currency_icon != '')? $currency_icon :'£'; $price =  get_field('price', $postid); $fprice = ($price != '')? $price :'99';  if( have_rows('origin-destination') ):      /* your_repeater_name corresponds name of repeater field */      // loop through rows of data     while ( have_rows('origin-destination') ) : the_row();      // or save sub fields in variable     $origin = get_sub_field('origin');     $destination= get_sub_field('destination');      endwhile;  else :      // no rows found  endif;   $zbor_text = (get_field('zbor_text')!='')?get_field('zbor_text'):''; $rr = get_field('zbor_images'); if(get_field('zbor_images')!=''){     $zbor_imagess = get_field('zbor_images');     $zbor_images = '';     foreach($zbor_imagess $zbor_image){         $imgurl = $zbor_image['url'];         $imgalt = $zbor_image['title'];         $imglink = ($zbor_image['alt']!='')?$zbor_image['alt']:'javascript:;';         $zbor_images .= '<a href="'. $imglink .'" target="_blank" style="display:block;"><img src="' . $imgurl . '" alt="'. $imgalt .'" /></a><br />';     } }else{     $zbor_images = ''; }    $cazare_text = (get_field('cazare_text')!='')?get_field('cazare_text'):''; if(get_field('cazare_images')!=''){     $cazare_imagess = get_field('cazare_images');     $cazare_images = '';     foreach($cazare_imagess $cazare_image){         $imgurl = $cazare_image['url'];         $imgalt = $cazare_image['title'];         $imglink = ($cazare_image['alt']!='')?$cazare_image['alt']:'javascript:;';         $cazare_images .= '<a href="'. $imglink .'" target="_blank" style="display:block;"><img src="' . $imgurl . '" alt="'. $imgalt .'" /></a><br />';     } }else{     $cazare_images = ''; }  $inchiriere_masina_text = (get_field('inchiriere_masina_text')!='')?get_field('inchiriere_masina_text'):''; if(get_field('inchiriere_masina_images')!=''){     $inchiriere_masina_imagess = get_field('inchiriere_masina_images');     $inchiriere_masina_images = '';     foreach($inchiriere_masina_imagess $inchiriere_masina_image){         $imgurl = $inchiriere_masina_image['url'];         $imgalt = $inchiriere_masina_image['title'];         $imglink = ($inchiriere_masina_image['alt']!='')?$inchiriere_masina_image['alt']:'javascript:;';         $inchiriere_masina_images .= '<a href="'. $imglink .'" target="_blank" style="display:block;"><img src="' . $imgurl . '" alt="'. $imgalt .'" /></a><br />';     } }else{     $inchiriere_masina_images = ''; }   $transfer_aeroport_text = (get_field('transfer_aeroport_text')!='')?get_field('transfer_aeroport_text'):''; if(get_field('transfer_aeroport_images')!=''){     $transfer_aeroport_imagess = get_field('transfer_aeroport_images');     $transfer_aeroport_images = '';     foreach($transfer_aeroport_imagess $transfer_aeroport_image){         $imgurl = $transfer_aeroport_image['url'];         $imgalt = $transfer_aeroport_image['title'];         $imglink = ($transfer_aeroport_image['alt']!='')?$transfer_aeroport_image['alt']:'javascript:;';         $transfer_aeroport_images .= '<a href="'. $imglink .'" target="_blank" style="display:block;"><img src="' . $imgurl . '" alt="'. $imgalt .'" /></a><br />';     } }else{     $transfer_aeroport_images = ''; }  $escala_text = (get_field('escala_text')!='')?get_field('escala_text'):''; if(get_field('escala_images')!=''){     $escala_imagess = get_field('escala_images');     $escala_images = '';     foreach($escala_imagess $escala_image){         $imgurl = $escala_image['url'];         $imgalt = $escala_image['title'];         $imglink = ($escala_image['alt']!='')?$escala_image['alt']:'javascript:;';         $escala_images .= '<a href="'. $imglink .'" target="_blank" style="display:block;"><img src="' . $imgurl . '" alt="'. $imgalt .'" /></a><br />';     } }else{     $escala_images = ''; }  $button_one_text = (get_field('button_one_text')!='')?get_field('button_one_text'):'click here book'; $button_one_url = (get_field('button_one_url')!='')?get_field('button_one_url'):'#'; $buttonone = '<a class="offer-book-lnk" href="'.$button_one_url.'" target="_blank" rel="nofollow">'. $button_one_text .'</a>';  $button_two_text = (get_field('button_two_text')!='')?get_field('button_two_text'):'hotel comparison tool'; $button_two_url = (get_field('button_two_url')!='')?get_field('button_two_url'):'#'; $buttontwo = '<a class="offer-book-lnk" href="'. $button_two_url .'" target="_blank" rel="nofollow">'. $button_two_text .'</a>';  $zbor = ($zbor_text!='' || $zbor_images!='')? '[tabby title="zbor"]'. $zbor_text . '<br />' . $zbor_images:''; $cazare = ($cazare_text!='' || $cazare_images!='')? '[tabby title="cazare"]'. $cazare_text . '<br />' . $cazare_images:'';  $inchiriere_masina = ($inchiriere_masina_text!='' || $inchiriere_masina_images!='')? '[tabby title="inchiriere masina"]'. $inchiriere_masina_text . '<br />' . $inchiriere_masina_images:'';  $transfer_aeroport = ($transfer_aeroport_text!='' || $transfer_aeroport_images!='')? '[tabby title="transfer aeroport"]'. $transfer_aeroport_text . '<br />' . $transfer_aeroport_images:'';  $escala = ($escala_text!='' || $escala_images!='')? '[tabby title="escala"]'. $escala_text . '<br />' . $escala_images:'';  $output = ''; if(is_single() && $ftitle!='' && $price!=''){     $output .= '<div class="post_offer"><div class="offer-header"><div class="offer-pr"><div class="offer-pr-t"> from</div> <div class="offer-pr-v"><div class=""><div class="offer-pr-c">'.$fcurrency_icon .'</div><span class="price" style="font-size:30px;">'.$fprice.'</span></div></div></div> <h2 class="offer-tl editor-paragraph-tags">'.$ftitle.'</h2></div><div class="offer-rt-rd"><div class="offer-rt-rd-o"><div class="offer-rt-rd-lb">origin</div><div class="offer-rt-rd-lo">'.$origin.'</div></div><div class="offer-rt-rd-d"><div class="offer-rt-rd-lb">destination</div><div class="offer-rt-rd-lo">'.$destination .'</br></div></div><div class="offer-rt-rd-ico"></div></div>';     $output .= do_shortcode( $zbor . $cazare . $inchiriere_masina . $transfer_aeroport . $escala . '[tabbyending]');     $output .= '<div class="offer_footer"><!--<ul class="offer-book">                         <li class="offer-book-it">' . $buttonone . '</li>                         <li class="offer-book-it">' . $buttontwo . '</li>                 </ul>--></div></div>'; }  $content .= $output; return $content; 

your first code sample not make sense, overwriting values of $origin , $destination. furthermore if want couple origin , destination values, should setup acf field follows: 1 repeater , 2 repeater sub-fields origin , destination

to loop through repeater values in frontend, use structure this:

<?php  // check if repeater field has rows of data if( have_rows('your_repeater_name') ):      /* your_repeater_name corresponds name of repeater field */      // loop through rows of data     while ( have_rows('your_repeater_name') ) : the_row();          // display sub field (the function the_sub_field echos values directly)         the_sub_field('origin');        /* sub-field name "origin" */         the_sub_field('destination');   /* sub-field name "destination" */          // or save sub fields in variable         $origin = get_sub_field('origin');         $destination= get_sub_field('destination');          // , echo them         // need output them **inside** while loop         echo $origin;         echo $destination;       endwhile;  else :      // no rows found  endif;  ?> 

applied scenario, assuming have functions.php , page-template:

add functions.php:

note, have check acf-field-names match code. repeater field in example called "your_repeater_name".

function print_origin_dest(){      // check if repeater field has rows of data     if( have_rows('your_repeater_name') ):          // loop through rows of data         while ( have_rows('your_repeater_name') ) : the_row();              // acf values             $origin = get_sub_field('origin');             $destination= get_sub_field('destination');              // add title , icon html here (you have not defined them in question)             $ftitle = 'your title';             $fcurrency_icon = '';              // render content             $output = '<div class="post_offer"><div class="offer-header"><div class="offer-pr"><div class="offer-pr-t"> from</div> <div class="offer-pr-v"><div class=""><div class="offer-pr-c">'.$fcurrency_icon .'</div><span class="price" style="font-size:30px;">'.$fprice.'</span></div></div></div> <h2 class="offer-tl editor-paragraph-tags">'.$ftitle.'</h2></div><div class="offer-rt-rd"><div class="offer-rt-rd-o"><div class="offer-rt-rd-lb">origin</div><div class="offer-rt-rd-lo">'.$origin.'</div></div><div class="offer-rt-rd-d"><div class="offer-rt-rd-lb">destination</div><div class="offer-rt-rd-lo">'.$destination .'</div></div><div class="offer-rt-rd-ico"></div></div>';              echo $output;          endwhile;      else :          // no rows found      endif; } 

then in page-template, call function:

<?php print_origin_dest(); ?> 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -