Home › Forums › ACF PRO › how to export ACF fields definition in JSON using PHP › Reply To: how to export ACF fields definition in JSON using PHP
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);
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.