Support

Account

Home Forums General Issues Get Option from WPML default language

Solving

Get Option from WPML default language

  • Hi – I’m after some help combining WPML and ACF Pro.

    I’ve got an Options page in English, which contains a phone number in a text field, which is then output in the site header.

    When the language is switched to another (Welsh in this case), is there a way of querying the field value from the English/default language Options page?

    The value will always be the same across both languages, so I’m looking for a way to not have to update it in every language each time an option needs changing.

    The solution I’ve tried so far just returns an empty string on Welsh pages:

    global $sitepress;
    $sitepress->switch_lang( $sitepress->get_default_language() );
    
    	the_field('phone_number', 'option');
    
    $sitepress->switch_lang( ICL_LANGUAGE_CODE );
  • I also need this, did you manage to solve it?

    Alternatively is there a way to manage content between Options Pages in the same way as Pages/Custom Post Types? e.g. When on an Options Page (English) being able to duplicate the content across and define how you want each field to work e.g. Copy, Translate, Don’t Translate

  • Yeah, put this in your functions.php:

    /**
     * Advanced Custom Fields Options function
     * Always fetch an Options field value from the default language
     */
    function cl_acf_set_language() {
      return acf_get_setting('default_language');
    }
    function get_global_option($name) {
    	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;
    }

    Then for usage, it’s: get_global_option('phone_number');

    Credit goes to indrek_k in this thread: http://support.advancedcustomfields.com/forums/topic/wpml-acf-5-0-9-and-options-page/

  • Great, thanks mate will give this a go.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Get Option from WPML default language’ is closed to new replies.