Support

Account

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);