How to count the number of ACF rows that have values?


I’m trying to count the number of acf rows that are storing values.

The field is a repeater field and all rows are standard text fields. They are available on as a user meta field.

Some users won’t use all of these rows, and may only have 1 or 2 rows with values in them.

So I know I can count rows like this

  function count_user_items() {
    $userId = get_current_user_id();
     if(have_rows('items', "user_{$userId}")) {
          while(have_rows('items', "user_{$userId}")) {
           $row = the_row();

           if(is_countable($row)) {
             $rows = count($row);

           return $rows;

However, this always returns 10 which is the maximum number of rows. How can I get this to count only the rows with values inserted?

dylzee 5 months 0 Answers 59 views 0

Leave an answer