This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Tagged: Custom Work
This topic contains 3 replies, has 0 voices.
Last updated by Itamar 1 month, 2 weeks ago.
Assisted by: Itamar.
| Author | Posts |
|---|---|
| February 26, 2026 at 2:34 pm #17857028 | |
|
Vincent Dagenais |
I have a custom field in a user profile that I want to translate. |
| February 26, 2026 at 4:24 pm #17857444 | |
|
Itamar WPML Supporter since 02/2016
Languages: Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+03:00) |
Hi, I've escalated this issue to our second-tier supporters. I appreciate your patience. |
| February 27, 2026 at 1:08 pm #17859808 | |
|
Vincent Dagenais |
I tried using this code update_user_meta($user_id, $meta_slug, $value); do_action( do_action( But even then I get the french register as english , and the english version is not sync with the french I have also tried seitching language whit do_action('wpml_switch_language', 'fr'); and switch back to original language. And do the same thing for english. Nothing worked. As you can see on the image, the french text was imported as english not french. **** Another point **** |
| March 1, 2026 at 2:25 pm #17862755 | |
|
Itamar WPML Supporter since 02/2016
Languages: Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+03:00) |
Hi, Our third-tier supporter suggests the following. (He stressed the point that the suggested code was not tested by him.) Our third-tier supporter wrote that you can import fields suffixed with a language code, such as "address-de", "address-fr", etc., and then filter by language code. For example, if you are using get_user_metadata, you can filter like this:
<?php
add_filter('get_user_metadata', function ($value, $object_id, $meta_key, $single) {
// Only intercept specific base keys (avoid global side effects).
$keys_to_localize = ['address']; // add more if needed
if (!in_array($meta_key, $keys_to_localize, true)) {
return $value;
}
// Detect language
$lang = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : null;
if (!$lang && function_exists('apply_filters')) {
$lang = apply_filters('wpml_current_language', null);
}
if (!$lang) {
return $value; // WPML not active / unknown
}
// IMPORTANT: prevent recursion by directly calling get_metadata_raw()
// Use WordPress core function if available; otherwise fall back.
$localized_key = $meta_key . '-' . strtolower($lang);
// If localized exists, use it; else leave default behavior
$localized = get_user_meta($object_id, $localized_key, $single);
if ($single) {
return ($localized !== '' && $localized !== null) ? $localized : $value;
}
return !empty($localized) ? $localized : $value;
}, 10, 4);
We hope this information is helpful to you. As for the other point, please see the other ticket. Regards, |
