[Resolved] Get Buddypress profile field's translated data
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:
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.
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?
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)?
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.--
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).
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.
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.