Support

Account

Home Forums General Issues Get Option from WPML default language

Solving

Get Option from WPML default language

    • Garyrae

    • February 10, 2015 at 10:28 pm

    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

    • Garyrae

    • February 18, 2015 at 8:48 pm

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.