Feature Request - Alt format for pulling ACF Group fields

I have a feature request for a new format to pull ACF Field groups.

Currently having to do a loop is pretty cumbersome just to pull a single field.

<Loop acf_group=group_field_name>
  <Field sub_field_name />
</Loop>

In Beaver Builder loop syntax, you can do this by [wpbb post:acf type='number' name='group_field_name_sub_field_name']

So basically you can just give the field name with an _ between them. L&L could pick whatever delimiter y’all wanted, but just being able to do <Field group_field_name_sub_field_name /> would be a dream.

This already works! <Field group_field_name_sub_field_name /> pulls the field value for me. Does it not work for you?

1 Like

Haha, I didn’t even try because it wasn’t in the docs

https://docs.loopsandlogic.com/102/advanced-custom-fields?category_id=83#group

It must be a native ACF thing if both BB and L&L support it!

Whaaat! Well that’s neat. Added it to the docs but I haven’t tested it myself so let me know if my understanding of how it works is correct. Are there any other fields that work this way?

I just did some quick digging in the acf docs and it looks like it might work for any subfield.

So I guess you could do it for a repeater? But I don’t know how that would be useful…

Are there any other fields that work this way?

Looks like this shortcut of combining parent and child field names with _ is specific to the Group field type.

The Group field uses both the parent and child field names when saving and loading values. For example, a Group field named ‘hero’ with a sub field named ‘image’ will be saved to the database using the meta name ‘hero_image’.

From: ACF | Group

(It might have been better to use double underscores __ to avoid any possible conflict with parent/child fields that include _ in them already. For example, a field called book_author might conflict with a parent field called book with child field author.)


But the Field tag itself has a shortcut for accessing a subfield. It can be seen in some of the field type examples, like:

<Field acf_file=field_name field=title />
<Field acf_image=field_name field=url />

I haven’t tried it, but it looks like it may work with the Group field type.

<Field acf_group=group_field_name field=sub_field_name />

This shortcut syntax wouldn’t work for repeater or flexible content, because those field types can have more than one child field. Theoretically we could add a field_index attribute to make that possible.

2 Likes

Cool. I’ll test it out sometime.

I agree that it is strange that ACF chose an underscore for that. :man_shrugging:t3:

I was looking at my old Topics and I saw this one. @benjamin and for anyone’s general knowledge, you can do it for repeaters too if you specify the row. So like <Field repeater_field_name_0_sub_field_name /> where the 0 is the index of the row you’re pulling (with 0 being the first)

2 Likes