Home › Forums › ACF PRO › Manually trigger acf-json sync › Reply To: Manually trigger acf-json sync
This is working well for me, with the option to make the loaded fields editable or not:
/* Default ACF fields */
function my_default_acf_fields() {
if ( ! acf_get_field_groups() ) {
$acf_json_data = @file_get_contents ( MY_PLUGIN_DIR . 'vendor/acf-json/my-acf-groups.json' );
if ( $acf_json_data && $custom_fields = json_decode( $acf_json_data, true ) ) {
foreach ( $custom_fields as $custom_field ) {
acf_import_field_group( $custom_field ); // editable
// acf_add_local_field_group( $custom_field ); // not editable
}
}
}
}
add_action( 'acf/init', 'my_default_acf_fields' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.