Support

Account

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