Friday, February 26, 2016

WP - ACF get_field problems with WPML

If you find your get_field('field_name', post_id) not working sometimes in your WPML site, you can try this trick:


global $sitepress;
$current_lang = $sitepress->get_current_language(); //save current language
$sitepress->switch_lang("en");

get_field('field_name');

$sitepress->switch_lang($current_lang);

This will temporary change the langauge of site, to enable get_field to get proper data. This could be some kind of bug in WPML/ACF combinations. Needs further checking.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...