Support

Account

Home Forums ACF PRO ACF PRO 5.6 & WPML – option page Reply To: ACF PRO 5.6 & WPML – option page

  • Yea, unfortunately WPML and ACF works nicely together ONLY if you don’t change “post_id” to something different than “options“, if you want to use something like “sidebars” for example, than translations for your options page stop working and updating options page on other language will overwrite other ones, or I assume it just updates it as not even trying to update for current language and separate from other ones 🙂

    I managed to fix this issue like this:

    // Get language suffix if not default language
    function getTheLang(){
            if( function_exists('icl_get_languages')){
                global $sitepress;
                $default_lang = $sitepress->get_default_language();
                $lang = ICL_LANGUAGE_CODE;
                if($lang != $default_lang) return '_'.$lang;
            }
            return '';
    }
    
    // Add custom options page
    acf_add_options_page(array(
                'page_title' => 'Sidebars composer',
                'menu_title' => 'Sidebars composer',
                'post_id' => 'sidebars' . getTheLang(),
                'parent_slug' => 'themes.php',
    ));

    To load a field, just add “getTheLang()” after your custom options “post_id”, like this for example:
    get_field( ‘sidebars’, ‘sidebars’ . getTheLang() );

    Nut much changed/hacked there, but this is works nicely 🙂