fbpx
Awesome

Convert an ACF Field Group from PHP to ACF-JSON

I was working on a legacy project recently that had a multiple Advanced Custom Fields – field groups registered with PHP. It was difficult to edit these hard coded field groups so I decided it was best to switch these to JSON. I ran the snippet below once, it converts each of the field groups from PHP into JSON and save these JSON files to the acf-json directory.

<?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 );
}

This is a Hookturn plugin ad block

This is a Hookturn plugin ad block

Built by Hookturn

This site was created by Hookturn, the team behind ACF Theme Code Pro. If you are interested in contributing or have an extension to add, email us.

Sponsored by Pressidium

Awesome ACF is sponsored by the very awesome team at Pressidium. If you need reliable, secure and scalable Managed WordPress Hosting, check them out.

Stay up to date with all things ACF

TODO: Registration form here