-
-
Save ValeriiVasyliev/f4ccebb2b34ff5cba36bcf4dc0a6c636 to your computer and use it in GitHub Desktop.
Load exportd JSON ACF fields via PHP – https://dev.to/jacobdb/import-acf-fields-via-php-without-losing-importability-5a8o/
This file contains hidden or 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 | |
/** | |
* 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