Forked from mishterk/acf-field-group-php-to-json.php
Last active
January 23, 2024 05:57
-
-
Save daniloparrajr/9b8d0c92e202c87f815b47dc8a162bba 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 | |
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