Get number of items in a structure field

Hi there.

I’m working on a bit of code where it’s supposed to put a random entry from an established structure field, but I’m having troubles figuring out how to check “How many items are in this structure?”

I tried $page->foo()->toStructure()->length();, but that came back empty. And $page->foo()->toStructure()->length(); came back as as 106, which i assume is the character count in the field.

Is there a field method I’m overlooking?

Thanks in advance.

The count() method should do the job:

$page->foo()->toStructure()->count();
2 Likes

Sure did! Thanks @texnixe.