The best solution I have found so far is to manipulate the field after on load
function fb_change_layouts( $field ){
$field['layouts'] = …
return $field;
}
add_filter( 'acf/load_field/key=field_6576a2f9f2147', 'fb_change_layouts');
Thank you for your patience.
I actually meant that I get the complete nested array of a repeater with get_field() with field keys instead of field names.
After researching for a while, I realized that the last parameter format does exactly that. This gives me field keys instead of names.
I have now found a solution that works quite well:
1.) I use acf_get_field_group() to read in the field group that I would like to display in my boxes.
2) With acf_get_fields() I get the corresponding fields in an array and can cycle through them.
3) With acf_get_field() I get the field object in the loop that I need later to display the field.
4) With get_field() and the last parameter set to false, I get the representation of the data that has already been saved for this field
5) I pass all this to acf_render_field_wrap() and so get the representation of the control in my box
Finally, I need to make it possible to have several boxes with the nested fields at the same time. At the moment it is only possible with one box.
I have solved the problem. For repeaters and flexible layouts, the field keys must be specified for the values instead of the names in the associative array.
However, this makes it very complicated with flexible layouts, as I have to work through the whole array and find the right key for each name in order to replace it.
Can I somehow retrieve values with field keys instead of field names? Is there a similar function to get_fields for this?
After our exchange yesterday, I thought everything through again today.
I have created a new field based on the boilerplate.
I now use a single field group that I want to display in my boxes for editing. In the render_field() function, I can read the field group with acf_get_field_group() and output the fields accordingly in my boxes with acf_render_field_wrap().
For saving, I retrieve the data from $_POST and place my box identifier, e.g. {$box_field_name}_{$field_name}, in front of the post_meta keys. This works with simple text fields, but reading in and out repeaters is more difficult.
The correct number of lines are displayed and saved, but the values remain empty. What could be the reason for this?
if(isset($field_object['sub_fields'])){
foreach ($field_object['sub_fields'] as $sub_field) {
$field_value = get_field($sub_field['key'], $id);
$acf_render_subfield_attributes[] =
array(
'type' => $sub_field['type'],
'name' => $sub_field['name'],
'value' => $field_value,
'key' => $sub_field['key'],
'label' => $sub_field['label'],
'instructions' => $sub_field['instructions'],
'required' => $sub_field['required']
);
}
}
$acf_render_attributes['sub_fields'] = $acf_render_subfield_attributes
Which types are available for render_field_settings. Can I use something like subfields?
That is helpful. In principle, I could create my own field type that works in a similar way to the repeater.
Is there a boilerplate for this or do I need to internalise the code from the repeater to create a similar field?
The meta key will somehow look like this:
{$parent_name_box}_{parent_name_flex-field}_{$row_index}_{$sub_field_name}
But as far as I can tell, I can display the same field group in as many instances as I want, right?
For example, I have created a flexible content field group that I can repeat any times using a repeater.
That would also help me if there was such a solution.
Thanks to the flexible content field, the group can actually be put together flexibly. There is no need for different field groups in different boxes. It can only be the one field group that is repeated in all boxes.
I think the actual representation of the fields in the editing is my main concern. The boxes should make use of the CSS grid so that complex grid layouts can be created in the backend.
I want to be able to display not only columns in a row, but also cells that span two rows. I would like to be able to display this in the admin area. That is the reason for the custom layout.
Thank you John for your feedback.
What I’m reading here is that each box needs a unique parent assignment in ACF, much like a repeater field. As I understand it, it would therefore make sense to create the layout as a separate ACF field.
The repeater function is in itself a good basis for the idea I have in mind, except that each row can have different attributes, not just the index.
Is it possible to create a field directly on the repeater field, or to extend it and customize functions?
I have already created my own fields, but no fields with nested field groups inside.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.