Home › Forums › General Issues › Error – count(): Parameter must be an array › Reply To: Error – count(): Parameter must be an array
I’m not sure if we’re on the same page. My problem is specificially with ACF Repeater fields. And yes, the fields are there & have content, they are output on the page. But I cannot count them with “count()”.
The repeater code as per ACF example:
<?php
// Check rows exists.
if( have_rows('repeater_field_name') ):
// Loop through rows.
while( have_rows('repeater_field_name') ) : the_row();
// Load sub field value.
$sub_value = get_sub_field('sub_field');
// Do something...
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
Now if I add count “$count = count(get_field(‘repeater_field_name’) );” , it doesn’t work:
<?php
// Check rows exists.
if( have_rows('repeater_field_name') ):
$count = count(get_field('repeater_field_name') );
// Loop through rows.
while( have_rows('repeater_field_name') ) : the_row();
// Load sub field value.
$sub_value = get_sub_field('sub_field');
// Do something...
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
My question – what code do I need to count how many repeats I have?
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.