You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, first of all, thank you very much for the much needed plugin that allows ACF Options to be linked with Polylang, I am happily using it on several sites already.
My question/feature request: is there a way to retrieve an option in a different language than the one currently being used on the frontend? Say I am browing the English version of the website, but I need to get an option value of a German version. I could naturally do it via WPDB, but I am hoping there is/could be another way, maybe as a param to a method, where the default value would be the currently used language?
Something along the lines if beapi_get_option($name, $language = pll_current_language()) {}
The text was updated successfully, but these errors were encountered:
/** * Get a value from an ACF options page for a specific locale * The locale must adhere to the WordPress standard (e.g. `en_GB` or `de_DE_formal`...) * * @param string $key The ACF field key * @param string $options_id The ACF options page's post_id * @param string $locale The locale. * @param array $args { * Optional array of arguments. Will be forwarded to ACF's get_field * * @param boolean $format_value Should the value be formatted? * @param boolean $escape_html Should HTML be escaped? * } */functionget_options_field_for_locale(
string$key,
string$options_id,
string$locale,
array$args = []
): mixed {
$locale_filter = fn() => $locale;
// Overwrite the current locale
add_filter('acf/settings/current_language', $locale_filter);
// Allow passing additional optional args to ACF's get_field()$args = array_merge([
'format_value' => true,
'escape_html' => false
], $args);
$result = get_field($key, $options_id, ...$args);
// reset the filter
remove_filter('acf/settings/current_language', $locale_filter);
return$result;
}
Hi, first of all, thank you very much for the much needed plugin that allows ACF Options to be linked with Polylang, I am happily using it on several sites already.
My question/feature request: is there a way to retrieve an option in a different language than the one currently being used on the frontend? Say I am browing the English version of the website, but I need to get an option value of a German version. I could naturally do it via WPDB, but I am hoping there is/could be another way, maybe as a param to a method, where the default value would be the currently used language?
Something along the lines if beapi_get_option($name, $language = pll_current_language()) {}
The text was updated successfully, but these errors were encountered: