Home › Forums › General Issues › Error – count(): Parameter must be an array › Reply To: Error – count(): Parameter must be an array
You need to get and count a repeater before you loop over the repeater with have_rows(). Trying to count the rows while inside the have_rows() loop for that repeater will have unexpected results.
$count = count(get_field('repeater_field_name') );
if (have_rows('repeater_field_name') {
// code continues
For this reason you need to test the repeater before you try to count it.
$count = 0;
$repeater = get_field('repeater_field_name');
if (!empty($repeater)) {
$count = count($repeater);
}
if (have_rows('repeater_field_name') {
// code continues
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.