Home › Forums › General Issues › How to display the number of the row of the repeater field ?
Hello,
How to display the number of the row of the repeater field please ?
In my project, one row = one step, so I want to display the left number of the row (in admin) on front office :
row 1 -> step 1
row 2 -> step 2
etc
I hope my explanation is clear.
Thanks in advance !
Hi!
Since you’re probably outputting the repeaterfield in a while loop you can use a counter for the steps:
<?php
$i = 1;
while(has_sub_field('myrepeaterfield')):
?>
<p>Step <?php echo $i; ?></p>
<?php
$i++;
endwhile;
?>
Hi @Manuc
You can also treat the repeater field value as an array:
echo count( get_field('repeater_field') );
This doesn’t seem to work inside a flexible content loop. The return from get_field() is NULL. I tried get_sub_field() and that returns false. Any suggestions?
Do you have it set up like this example?
http://www.advancedcustomfields.com/resources/flexible-content/
Hi, What was the resolution to this? I’m having the same issue of getting a null result from a repeater in a flexible content field in a repeater. I’m pretty sure I have it set up correctly…
@zaccety I think I figured out it had something to do with the placement of the function call. See here: https://github.com/solepixel/acf-modules/blob/master/modules/icon-blocks.php#L242
Notice that it’s outside “have_rows”. I’m pretty sure that’s all I needed to do and it returns the correct amount.
Thanks for the reply, looks like you’re doing something a lot more complicated than what I’m trying to achieve :c) turned out I had a rookie syntax error :c|
Hi everyone,
I’d like to go a little further (and more complicated):
Is it possible to count the number of row with a true/false field on “true”.
@meneldil My quick go to your question as I was searching for the answer myself.
if( have_rows('my_repeater') ):
$i = 0;
while( have_rows('my_repeater') ): the_row();
if( get_sub_field('sub_field_boolean') ) $i++;
endwhile;
$tCount = $i;
endif;
($tCount to produce the number of rows with a true field)
I’ll consider this issue as solved now. Seems all questions have been answered?
The topic ‘How to display the number of the row of the repeater field ?’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.