Home Forums Add-ons Repeater Field Empty Group have_rows is true?


Empty Group have_rows is true?

  • I’m using a Group field to organize a section of fields and I have a post that is saved, but has no sub fields in the group. Still when I call the have_rows method on that group it is returning a value of true. Why?

  • I haven’t really used a group field before and I just did some quick testing. It appears that a group is basically a repeater with 1 row and the field always has 1 row if the post or admin page it’s on has been saved since the field in the group will always have a value, even if the value is false/null/empty or whatever.

  • That has been my experience as well. So what I’m wondering now is, is this a bug or intended functionality? Since, as you said, it’s like a Repeater and the check seems to be have_rows no rows in a Repeater is false yet here with a Group evaluates to true. I would argue it’s a bug.

  • I think that it’s intended.

    If the post has never been saved then the group has no rows but if it has been saved it will always have one row even if all the fields in the group have no value.

    I think that using have_rows() is just a convenience so that you can reference the fields without the group field name prefix.

    For example, lets say that you have a group field with the name of “group” and it has 2 sub fields; “field_1” and “field_2”.

    You can access these fields like this:


    or for the convenience of not added the field names together you can do:

    while (have_rows('group')) {

    have_rows() will always return true if the post has been saved.

    Think of a regular repeater that has several sub fields but none of them are required. If you add a row to this repeater but do not enter any values into it the empty fields will be saved. This repeater will have one row even though no values have been entered into the existing row. The group field works the same way.

    If you think this is a bug you are free to open a new support ticket

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

You must be logged in to reply to this topic.