Support

Account

Forum Replies Created

  • Thank you very much John! Finally got it 🙂

    My mistake was to assume have_rows() is equivalent to “is not empty” or “exists” so I didn’t appreciate that placing my code inside have_rows() would not work.

    Got it & works perfectly now, thank you!

  • 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?

  • I’m getting the same error. Any help from the ACF team on this?

Viewing 3 posts - 1 through 3 (of 3 total)