Last active
September 1, 2022 12:29
-
-
Save joloco/5c766b27f7bd272837a6392570824d2c to your computer and use it in GitHub Desktop.
Surprisingly simple way to import fields into ACF GUI from PHP code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// To re-import ACF settings from acf_add_local_field_group() into the ACF wp-admin GUI | |
$group_key = 'group_111222333'; // This must match the key as defined at the top of acf_add_local_field_group() | |
//After the field group is completely set up, get the field group. | |
$group = acf_get_field_group($group_key); | |
// then get the fields for the group | |
$group['fields'] = acf_get_fields($group_key); | |
// output JSON for saving into a file | |
echo(json_encode($group)); | |
die(); | |
/* | |
// or write the field group to a file | |
$filename = '/path/to/your/file.json' | |
$handle = fopen($file, 'w'); | |
fwrite($handle, json_encode($group)); | |
fclose($handle); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment