Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ValeriiVasyliev/f4ccebb2b34ff5cba36bcf4dc0a6c636 to your computer and use it in GitHub Desktop.
Save ValeriiVasyliev/f4ccebb2b34ff5cba36bcf4dc0a6c636 to your computer and use it in GitHub Desktop.
<?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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment