Skip to content

Instantly share code, notes, and snippets.

@justinhough
Created November 13, 2019 06:49
Show Gist options
  • Save justinhough/aba00fccfa4f878d0d940d1ebc6de441 to your computer and use it in GitHub Desktop.
Save justinhough/aba00fccfa4f878d0d940d1ebc6de441 to your computer and use it in GitHub Desktop.
WP Advanced Custom Fields - Save and Load via JSON
<?php
/**
* ACF Custom Fields - Save and Load
*
* When ACF fields are added or updated this will save the output to JSON
* where they can be version controlled and loaded on Production sites.
* For best usage the production database should not contain any ACF
* in the database.
*
* @package
*/
function my_acf_json_save_point( $path ) {
// update path
$path = get_stylesheet_directory() . '/custom-fields';
// return
return $path;
}
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
function my_acf_json_load_point( $paths ) {
// remove original path (optional)
unset($paths[0]);
// append path
$paths[] = get_stylesheet_directory() . '/custom-fields';
// return
return $paths;
}
add_filter('acf/settings/load_json', 'my_acf_json_load_point');
@justinhough
Copy link
Author

Create a separate file include file that gets added to functions.php like so, require get_template_directory() . '/inc/acf.php';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment