Hi Folks,
I am having an issue with adding a repeater field to my site.
Below is a screenshot of AFC in wp and then below that is the code I have added. What am I doing wrong.
https://drive.google.com/file/d/1tPwc5_SnorpJQ3z-Cwz4nDGMykBl5Eht/view?usp=sharing
<?php if( have_rows(‘documents_area’) ):
while( have_rows(‘documents_area’) ) : the_row(); ?>
<p><?php $sub_value = get_sub_field(‘document_text’); ?></p>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
You need to echo the field value, not just return it. get_sub_field()
is for returning it (i. e. to store it in a variable and do something with it afterwards), and for directly echoing it you would use the_sub_field()
(spot the little difference between “get” and “the”).
However, you can, of course, also go the little detour of storing the value in a variable and then echoing that variable; so, in your example, you would do:
$sub_value = get_sub_field(‘document_text’);
…
…
echo($sub_value);