Last active
February 8, 2018 10:15
-
-
Save harisrozak/2943fd17f3c264bbefb3990a2cf752ae to your computer and use it in GitHub Desktop.
WordPress :: Get ACF option field on WPML multi languages
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 | |
// display current language | |
if ( defined( 'ICL_LANGUAGE_CODE' ) ) { | |
echo "<pre>Current language code: "; | |
print_r(ICL_LANGUAGE_CODE); | |
echo "</pre>"; | |
} | |
// get all WPML languages | |
$langs = icl_get_languages('skip_missing=0&orderby=KEY&order=DIR&link_empty_to=str'); | |
// get acf option "seo_title" in all languages | |
foreach ($langs as $lang) { | |
// modify current language | |
add_filter('acf/settings/current_language', function() { | |
global $lang; | |
return $lang['code']; | |
}); | |
echo "<pre>seo_title [{$lang['code']}]: "; | |
print_r(get_field('seo_title', 'option')); | |
echo "</pre>"; | |
} | |
// reset to original language | |
add_filter('acf/settings/current_language', function() { | |
return ICL_LANGUAGE_CODE; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment