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 π
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and donβt forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
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.