Support

Account

Home Forums Add-ons Repeater Field Repeater Field Displaying Only the Last Row

Solved

Repeater Field Displaying Only the Last Row

  • Hi,

    I have this repeater field called “news” and its subfield is also called “news.” The thing is that I have three subfields but only the last field shows up.

    I have this code;

    			<?php
     
    			if( get_field('news') )
    			{
    				while( has_sub_field('news') )
    				{ 
    					$news = get_sub_field('news');
    				}
    			}
    				?>		
    				<?php echo $news; ?>
    
    			<?php endwhile; endif; ?>

    Thanks!

  • By having just $news = get_sub_field('news'); every time your while loop loops through the array, you’re overwriting the $news variable, if you do $news .= get_sub_field('news'); you’ll be appending to it instead.

    Sorry if that doesn’t make much sense, I am apparently rotten at explaining things. <.<

  • Hm, one problem is that, the rows appear all in one line, i.e., there’re no line breaks. Could you help me with it please?

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

The topic ‘Repeater Field Displaying Only the Last Row’ is closed to new replies.