Skip to content

Instantly share code, notes, and snippets.

@harisrozak
Last active February 8, 2018 10:15
Show Gist options
  • Save harisrozak/2943fd17f3c264bbefb3990a2cf752ae to your computer and use it in GitHub Desktop.
Save harisrozak/2943fd17f3c264bbefb3990a2cf752ae to your computer and use it in GitHub Desktop.
WordPress :: Get ACF option field on WPML multi languages
<?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