Hi,
I use ACF embedded in my themes/plugins. For registering the ACF fields at runtime I use the JSON file created using tools/export feature of ACF.
I would like to automatize the building process, so I would like to have a PHP code that giving the ACF Group IDs generate the related JSON.
Thanks
You can use the function acf_get_field_group($id)
to get a field group. $id
can be either the field group key or the post ID of the field group.
You can use the function acf_get_fields($id)
to get the fields in the field group. Again $id
is either the field group key or the post ID of the field group.
Putting them together
$field_group = acf_get_field_group($id);
$field_group['fields'] = acf_get_fields($id);
If you want to just json encode them you’d just do
$json = json_encode($field_group);
If you want the save it to a file and you want it pretty the way that ACF saves field groups, ACF has another function that you can use.
$json = acf_json_encode($field_group);