Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Read ACF fields from JSON
*/
function PREFIX_acf_register_json_fields() {
if (function_exists("acf_add_local_field_group")) {
$acf_json_data = locate_template("path/to/advanced-custom-fields.json");
$custom_fields = $acf_json_data ? json_decode(file_get_contents($acf_json_data), true) : array();
foreach ($custom_fields as $custom_field) {
acf_add_local_field_group($custom_field);
}
}
}
add_action("init", "PREFIX_acf_register_json_fields");
@swinggraphics

This comment has been minimized.

Copy link

swinggraphics commented Jan 24, 2020

For anyone looking to do the same thing, except make the fields editable, change acf_add_local_field_group to acf_import_field_group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.