Last active
October 9, 2023 08:01
-
-
Save michaeldeboeve/e13eaada243c31f6face0c779fc4e7fe to your computer and use it in GitHub Desktop.
wordpress - Fetch an ACF Options field value from the default language when empty (WPML/ACF)
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 | |
/** | |
* Advanced Custom Fields Options function | |
* Fetch an Options field value from the default language when empty | |
*/ | |
function cl_acf_set_language() { | |
return acf_get_setting('default_language'); | |
} | |
function get_global_option($name) { | |
$option = get_field($name, 'option'); | |
if(empty($option)) { | |
add_filter('acf/settings/current_language', 'cl_acf_set_language', 100); | |
$option = get_field($name, 'option'); | |
remove_filter('acf/settings/current_language', 'cl_acf_set_language', 100); | |
} | |
return $option; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment