How to count the total number of rows in a ACF repeater output How to count the total number of rows in a ACF repeater output wordpress wordpress

How to count the total number of rows in a ACF repeater output


OK, I finally found the answer to this.

The way to count total rows in an ACF repeater is:

$numrows = count( get_sub_field( 'field_name' ) );


You can get the row count like this:

$count = get_post_meta(get_the_ID(), 'testimonials', true);

Obviously this uses get_the_ID() to retrieve the current post ID - you may need to amend this.

ACF stores the repeater count value against the repeater field name as the meta_key in the postmeta table.

ACF uses the count to retrieve the correct repeater subfield values, which are stored as values against meta_keys with the format $repeaterFieldname . '_' . $index . '_' . $subfieldName.

Hope this helps...


You may wanted to try this..

<?php $row = get_field('repeater', $post->ID);if($row < 1) { $rows = 0;} else { $rows = count($row);} ?><p>Number of Row is (<?php echo $rows ; ?>)</p>