Home Forums Feature Requests Import from PHP Reply To: Import from PHP

  • There isn’t an way to import field groups from PHP and like @jonathan says, this is not likely to be something that the developer builds in. Anything to do this is going to be work. There are several ways.

    The first you mentioned, create a new field, export it and copy/paste the new field.

    another way is to just copy and paste an existing field definition that is similar to the new one you want and then edit the settings, make up a field key that will be unique.

    If you want to be able to work on the field then you can export the field yourself as JSON to import it. After the code that creates your field group is done and the field group is ready do the following

    $path = '/abs/folder/path/where/you/want/file/saved/';
    $json = acf_json_encode($group);
    $file_path = $path.$group['key'].'.json';
    $handle = fopen($file_path, 'w');
    fwrite($handle, $json);

    Something that I like to do when working on field groups is to create a local json folder in the them. This way the groups are automatically saved for me whenever I edit them. Then I save the files with the rest of the assets for a site or project. This way if I ever need to modify them I can simply import from this file and make the needed changes.