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);
fclose($handle);
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.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.