Home › Forums › General Issues › Move from PHP registered fields to ACF UI
Is it possible to move fields that have been registered PHP (in the functions files) to the ACF UI so they can be edited via WP Admin?
If so, is it possible to retain all of the existing values?
Getting them from PHP into ACF admin will depend on what version of ACF you are using.
The first step is to get the field group into a format that can be imported.
Just after you’ve created the field group in PHP you need to add some code (temporary) that will format the field group for importing and save it as a file. For ACF5 you just need to use
I don’t know how to tell you to format the group for ACF4. I think it uses a standard WP type of import XML file.
As far as keeping the values, as long as your field names and field keys are the same as those generated by PHP then none of your values will be lost.
Ok, we tried that but the output doesn’t look right.
Here’s the code we are running: https://www.dropbox.com/s/orqr1g69mr3p8m3/acf.php?dl=0
Thanks for the help so far John!
BTW, we are using ACF Pro Version 5.3.10
Once you have saved the json file you need to download it, remove the field group completely from your PHP and then import the field group into ACF. The regular json_encode() will look different than the ACF version because it does not include the white-space that ACF adds to the file, but you should still be able to import it.
I am the developer working on this project. I also hold an ACF pro license under this account. The JSON exported from the code above is not working and the fields are not imported after selecting any of the resulting files. Did you run the code in your local environment? Did it work for you?
Are you sure the json has the right values? For example, where is the “key” for each group? i see you are using an “id”, but…. shouldn´t be “key” ?
Also the entire json generated must be inside  and is not.
Also i notice you are using ‘options’ => array(…. but in my exported json from ACF UI, that thing do not exsits, position, hide_on_screen and so on are “alone” not as part of an array.
So, i think the array that is transformed into json is not well formated and that´s why when importing nothing happens.
Did you test with just a small and simple array let´s say a group with just one text field and no complex location rules?
Sorry, I only scanned your code minimally.
The first thing that I noticed in your code was this
This function that you’ve created already exists in ACF and the first line of your code should be causing a fatal error trying to declare the same function more than once. I did not look at every field group, but @rgdesign is correct. The field groups that you are attempting to create in PHP do not look like they are correct to begin with. My suggestion here is to create a field group in ACF and export them to PHP to get a better idea of what they need to look like in ACF5. There are significant differences between ACF4 and ACF5. if the field groups in your code were originally done for ACF4 then they will need to be updated to work with 5.
After registering your field groups as normal in ACF.
$field_group = acf_get_field_group($group_key); $field_group['fields'] = acf_get_fields($group_key'); $json = json_encode($field_group); file_put_contents($group_key.'.json', $json);
This should create a file that can be imported. Like I said, once the group is imported you need to delete it completely from your PHP or otherwise disable php from registering the group.
You must be logged in to reply to this topic.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.