Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daniloparrajr/9b8d0c92e202c87f815b47dc8a162bba to your computer and use it in GitHub Desktop.
Save daniloparrajr/9b8d0c92e202c87f815b47dc8a162bba to your computer and use it in GitHub Desktop.
Convert an ACF Field Group from PHP to ACF-JSON
<?php
add_action( 'acf/init', function() {
// 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'] );
foreach ( $group_fields as $field_key => $field_options ) {
if ( $field_options['type'] !== 'repeater' ) {
continue;
}
if ( acf_have_local_fields( $field_key ) ) {
$group_fields[ $field_key ]['sub_fields'] = acf_get_local_fields( $field_key );
}
}
$group['fields'] = $group_fields;
}
// Write the group's JSON file.
acf_write_json_field_group( $group );
}
}, 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment