Hi All
I have seen similar topics on the forums to do what I am trying to do but nothing quite right so I am hoping you guys can help me out.
I am developing a base theme that we can use as a basis for our projects that relies on having re-usable layouts that can be added to an ACF field group and used throughout the sites.
What I want to be able to do is select one of my layouts from a dropdown, then select the field group, and field within that field group that I want to install that layout to, it will then grab all the information that I have stored in an array for that layout, and add it as an available layout of the ACF field. I hope that makes sense!
I can’t find any documentation on how to actually programatically add a layout to an existing field in ACF. I did find something on another topic that mentioned something like this:
$field_data = acf_get_field($field);
$key = uniqid();
$field_data['layouts'][$key] = array(
'display' => 'block',
'key' => $key,
'label' => 'Test',
'max' => '',
'min' => '',
'name' => 'test',
'sub_fields' => array()
);
acf_remove_local_field($field);
acf_add_local_field($field_data);
However this doesn’t seem to do anything. I suspect this is something to do with the local_field part? It is worth noting that these fields are not adding using PHP in the functions file, they are added using the admin interface then cached into the acf-json files.
Any guidance would be greatly appreciated!!
Many thanks
David