Last active
June 21, 2024 19:28
-
-
Save mishterk/d3d3010b21771a94340d03738d5b0566 to your computer and use it in GitHub Desktop.
Convert an ACF Field Group from PHP to ACF-JSON
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 | |
// Get all the local field groups and loop through them for processing. | |
$field_groups = acf_get_local_field_groups(); | |
foreach ( $field_groups as $group ) { | |
// If the field group has fields, load them into the 'fields' key. | |
if ( acf_have_local_fields( $group['key'] ) ) { | |
$group['fields'] = acf_get_local_fields( $group['key'] ); | |
} | |
// Write the group's JSON file. | |
acf_write_json_field_group( $group ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@daniloparrajr, I suspect you may need to loop through fields within the field group and if they have sub fields, assign those to the field's
sub_fields
key.$group['fields']
value after it is assigned to see ifacf_get_local_fields()
gets sub fields as well?If you find a solution, suggest an adjustment so we can update the snippet.