Last active
October 8, 2019 05:27
-
-
Save mishterk/b25e7c045c85e9591a9c596060494c8c to your computer and use it in GitHub Desktop.
Define custom load points for Advanced Custom Fields (ACF) JSON files. For more info see https://philkurth.com.au/tips/how-to-get-advanced-custom-fields-to-load-json-files-from-more-than-one-directory/
This file contains 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 | |
add_filter( 'acf/settings/load_json', function ( array $directories ) { | |
$base_dir = get_stylesheet_directory() . '/components'; | |
$resource = opendir( $base_dir ); | |
while ( ( $file = readdir( $resource ) ) !== false ) { | |
// Skip current and parent directory references | |
if ( in_array( $file, array( '.', '..' ), true ) ) { | |
continue; | |
} | |
// Get the full path | |
$dir = "$base_dir/$file"; | |
// If we have a directory (not a file) add it to our ACF JSON load paths | |
if ( is_dir( $dir ) ) { | |
$directories[] = $dir; | |
} | |
} | |
closedir( $resource ); | |
return $directories; | |
} ); | |
This file contains 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 | |
add_filter( 'acf/settings/load_json', function ( array $directories ) { | |
// Define as many directories as necessary. ACF will look in each | |
// directory and load any JSON files it finds. | |
$directories[] = get_stylesheet_directory() . '/components/one'; | |
$directories[] = get_stylesheet_directory() . '/components/two'; | |
$directories[] = get_stylesheet_directory() . '/components/three'; | |
return $directories; | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment