kier0
10/20/2015 - 2:04 PM

How to get language independent ACF theme options on a WPML site

How to get language independent ACF theme options on a WPML site

<?php
/**
 * To get this to work, you need to tinker with the acf/settings/ filter and reset the default language
 * so that the get_field() function returns the correct results even when not on the default language.
 * 
 * You can add the filter before you call the get_field() function and then call it again with the current 
 * language to reset it again, so it will affect other pages.
 * 
 * answer courtesy of James of ACF Support
 */

// add this
add_filter( 'acf/settings/current_language', function() {
     global $sitepress;
     return $sitepress->get_default_language();
});

// this is already in your code
$my_field =  get_field( 'my_field', 'option' );

// reset to original language
add_filter( 'acf/settings/current_language', function() {
     return ICL_LANGUAGE_CODE;
});