Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are trying to display a translated profile field in a different section than the default Profile section on your website. Specifically, you have moved the field to the 'Profile header' using custom code, but the field displays in English instead of the selected language.
Solution:
To ensure the field displays in the correct language, you should use the

wpml_translate_single_string

hook instead of the

wpml_object_id

filter, as the latter is intended for filtering post types by ID. Here is how you can modify your code:

function render_member_header() {<br />  $expertise = xprofile_get_field_data('My Offer', bp_displayed_user_id(), 'comma');<br />  echo '<span>'. apply_filters('wpml_translate_single_string', $expertise, 'context', 'name') .'</span>';<br />}<br />add_action('bp_before_member_header_meta', 'render_member_header');

For more details on using this hook, please visit wpml_translate_single_string documentation.

If this solution does not resolve your issue or seems outdated, we recommend opening a new support ticket. Also, check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum.

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: 

This topic contains 6 replies, has 2 voices.

Last updated by Itamar 2 months, 4 weeks ago.

Assisted by: Itamar.

Author Posts
August 6, 2024 at 2:04 pm #16044362

arthurS-22

Background of the issue:
I would like to show data from a profile field (BuddyPress) at another part of my site (for example, at users' card on the Members page, etc.). I try to use 'xprofile_get_field_data' with this code: function render_extra_fields_data() { $options = xprofile_get_field_data('Options', bp_displayed_user_id(), 'comma'); echo esc_html($options); } add_action('bp_member_members_list_item', 'render_extra_fields_data'); But I got data only in English (default language).

Symptoms:
I am only getting data in English (default language) and not the translated data for each language.

Questions:
How can I get translated data of this field for each language?

August 6, 2024 at 7:57 pm #16045578

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

You are facing a known issue. Please read about it in the following link and apply the suggested workaround.

https://wpml.org/errata/buddypress-profile-fields-are-not-being-translated-on-the-frontend/

I also assume you use our BuddyPress Multilingual bridge plugin and follow our guide here.

https://wpml.org/documentation/related-projects/buddypress-multilingual/#translating-profile-fields

Can you please confirm this?

If you need further help with this issue, please share your site's Debug information. You can read about it here.

http://wpml.org/faq/provide-debug-information-faster-support/

Regards,
Itamar.

August 7, 2024 at 1:25 pm #16048237

arthurS-22

Hi Itamar,
thanks for your response!
I have no problem with translation of profile fields.
I translated them and they are displayed correctly on the user's profile page (for all languages). But I would like to show data from this fields at another part of my site. Please see attached picture.
How can I get translated data of this field (using xprofile_get_field_data function or smth other function)?

profile field.png
August 7, 2024 at 5:29 pm #16049514

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

I need to understand better what you are trying to achieve. Please let me access your site and explain in detail where and how to see the issue. If you can add a video, it would be great. You can use the free online screencast service Loom—hidden link. This should help me see if you did anything wrong.

If you need further help with this, please share the access details to your site with me. I'm enabling a private message for the following reply.

Privacy and Security Policy
We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/
**IMPORTANT**
- - Please backup the site files and database before providing us access. --
-- If you have a staging site where the problem can be reproduced, it is better to share access to the staging site.--

Thanks,
Itamar.

August 8, 2024 at 2:42 pm #16053486

arthurS-22

Hi Itamar,
ok, to begin with, I will try to explain with a picture:

#1.
I add a regular profile field and make a translation for it.
At picture (position #1 ) you can see German translation for field "My Offer", this is "Mein Angebot: Produkt, Handwerk".
So, here everything is ok. (when I switch language - I see translated variant)

#2.
I try to show this field not in Profile section (as default), but in another section. In my exemple (position #2 ) there is in "Profile header" (bp_before_member_header_meta).

I made this by next code:

function render_member_header( ) {
$expertise = xprofile_get_field_data('My Offer', bp_displayed_user_id(), 'comma');
echo '<span>'.esc_html( $expertise ).'</span>';
}
add_action( 'bp_before_member_header_meta', 'render_member_header' );

But, when I switch language - I'm always see English (not translated) variant.

So, my question is - how I should modify my code, to show translated variant of this field, which I obtained in this way.
Maybe with a help of "wpml_object_id" filter or smth else.

profile field.png
August 8, 2024 at 3:16 pm #16053592

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, and thanks for adding the details.

Custom code is out of the scope of our support forum. However, I've passed on your question to our second-tier supporters to see if they can explain how to achieve this.

I'll update you here once I have their reply.

Please note that my weekend is Friday-Saturday, and I'll be able to continue to check this issue and help you on Sunday.

Regards,
Itamar.

August 14, 2024 at 7:31 am #16069010

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

Here is the reply from our second-tier supporter.

wpml_object_id will only help if we try to filter a post type by ID.

If this is translated with String Translation, you needs to use the wpml_translate_single_string hook:

https://wpml.org/wpml-hook/wpml_translate_single_string/

I hope this will be helpful to you.

Regards,
Itamar.