It may not be the whole story but I’m trying to figure out why a seamless Clone field referencing the same field seems to stick an extra array around the output when it’s a direct field in a field group vs. a sub field of say a Repeater.
Output of the Clone field directly on a field group for a Custom Post Type using get_field (content_select is the ID of the cloned field):
Array ( [content_select] => Array ( [content_type] => whatever ) )
Output when used inside a Repeater with get_sub_field on a different Post Type gives just the cloned field’s sub fields:
Array ( [content_type] => whatever )
Trying to treat these the same and realized the different output. It’s not like a problem, I can treat them differently, I’m just curious why it is that they are different?
Both the Clone fields are set up identically (seamless, no prefixes, cloning the same field), except for where they are being placed (one inside a repeater).
Sorry to resurrect an old thread, but I’ve just been pulling my hair with the same issue on a new project.
It was proving very difficult to get fields and sub fields to match references, as I needed them to, for various template parts.
In my example,the client had a broad colour palette,and pretty much every page component (built using flexible content) could use any colour from the palette.
Rather than manually recreate the colour select field,I thought I’d be a bit more efficient and create a select field in a ‘brand options’ field group,and then clone that field whenever needed. For example:
– Hero banner
– – Title
– – Image
– – Colour (clone field)
– Flexible Content
– – CTA Box
– – – Title
– – – Text content
– – – Colour (clone field)
In the hero banner, the data is obtained by get_field,the CTA Box by get_sub_field. The colour field for the subfield was a Lot harder to get to.
I think part of my problem is that I quite like using unique field names, which isn’t necessary for nested content, becausevi findit easier for debugging.
In the OP @sbmatthisamoto‘s case I do not know the reason they are being returned differently. My understanding is that this should not be happening.
@curious-toad in one case your field is not a sub field and in the other it is. The only way to make them the same is to make the one that is not a sub field a sub field, for example of a group.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.