Skip Navigation

[Résolu] Displaying translated user-meta-fields (WPML domain "authors")

Ce fil est résolu. Voici une description du problème et la solution proposée.

1) Put this filter into functions.php and add ALL user-fields, which should be translated:

add_filter( 'wpml_translatable_user_meta_fields', 'add_usermeta', 99);
function add_usermeta( $fields ) {
    $fields = array('description','wpcf-my-custom-field');
    return $fields;
} 

2) Add the shortcode for displaying the user-fields in functions.php

add_shortcode( 'user-meta', 'user_meta_func');
function user_meta_func($atts) {
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

3) Add the shortcode in Toolset (Settings > Frontend > Shortcode-Arguments)
4) Add the shortcode wherever your fields should appear (in View, Layout, Page ...)

[user-meta id="[wpv-user field='ID']" key="description"]
[user-meta id="[wpv-user field='ID']" key="wpcf-my-custom-field"]
This support ticket is created Il y a 6 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 9 réponses, has 2 voix.

Last updated by dianaM-4 Il y a 6 années et 10 mois.

Assisted by: Christian Cox.

Auteur
Publications
#522037

Hi there! This is an issue regarding the Toolsets and the WPML-plugins. I already posted my question in the WPML-forum. They wanted me to ask here too.

I am trying to translate users with the role editor and show their infos as "business-cards" on Frontend. I'm working with WPMLs string-translation and Toolset Types and Views. I got the domain "authors" working for all these strings. There I translated all my user-meta but on the English site, the translated strings aren't showing. I did it this way:

* I created custom user-fields in Toolset Types and assigned them to all editors
* I made a Toolset View for showing all my editors as a list in Frontend
* In WPML-string-translation I marked "translation for user of type: editor"
* Then all my standard-user-fields showed off under the domain "authors"
* For translating the custom user-fields, which I created with Toolset Types, I added custom code to functions.php as described in this post: https://wpml.org/forums/topic/how-do-i-translate-the-contents-of-fields-in-the-user-profile/
* Then also my custom-user-fields appeared in the string-translation-list of domain "authors"
* I translated every string, marked as finished.

My custom code for adding the custom user-fields to string-translation:

add_filter( 'wpml_translatable_user_meta_fields', function( $fields ) {
    $fields = array('wpcf-team-pos', 'wpcf-team-zitat', 'wpcf-team-aufgaben', 'wpcf-team-ausbildung');
    return $fields;
} );

In my Toolset-Views I've added the standard-user-fields with:

[wpv-user field='user_firstname']

and the custom-user-fields with:

[types usermeta='team-zitat'][/types]

But the Frontend shows all the user-infos in my standard-language German, instead of English (neither the standard- nor the custom-user fields).

I already tried to:
* Disable all other plugins (than Toolset and WPML)
* Switched to Toolsets Starter Theme
* "Scan themes for strings" in WPMLs theme- and plugin-localization
* In WPMLs Support-Troubleshooting: Clear cache, delete ghost-entries
* Deleted all translated strings in Domain "authors", reloaded them and translated them again

Nothing worked. For all of my other views, which are showing other content (as pages or custom post types) the English Translation is automatically assigned to the English page. But for any reason in this view of user-fields, that doesn't work. There is still my German standard-language.

Is there another shortcode for that?
Please for help!

#522144

Hi, can you look for your strings under the domain "wpml-shortcode" instead of "authors"? If they appear, please add your translations here. We have had a couple of bugs recently where strings are registered under the wrong domain.

If the strings are not found under "wpml-shortcode", may I request access to your site so I can make a clone and run some tests locally? Private reply fields are enabled here.

#522145

Private reply fields enabled.

#522214

Hi Christian,
you got my access-details to my site. It’s not a live-site yet. So please feel free to test it there.

* The site, on which my user-infos should show up: nextpm.dianimation.at/en/#team
* There are two Toolset Views for this, both showing German instead of English.
* View for larger screens: ?page=views-editor&view_id=932
* View for smaller „mobile“-screens: ?page=views-editor&view_id=913
* WPML-string-translation for user-role "editor" is in Domain „authors“

No, there aren’t any new related strings in this new domain "wpml-shortcode". All my strings show up in the correct domain „authors“.

And neither the wordpress-standard-user-fields are showing the translated content, nor the custom-user-fields, which I created with Toolset.

In one of the WPML-forums I found a php-code, which should be placed to show the translated user-meta:

get_the_author_meta( 'user_url', $user_id );

But there should be a shortcode for that, shouldn't it?

#522282

Well I don't think you're doing anything wrong. I think this is just a limitation of WPML unfortunately, and I can see that translating user meta information has been added to the list of feature requests. In the meantime, I can wrap the get_the_author_meta function in a shortcode for you to use. Add this code to functions.php:

add_shortcode( 'get_types_user_meta_custom', 'get_types_user_meta_custom_func');
function get_types_user_meta_custom_func($atts)
{
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

Then you can use the following shortcode syntax whenever you want to display translated user meta information in your View's Loop:

Team Zitat: [get_types_user_meta_custom id="[wpv-user field='ID']" key="wpcf-team-zitat"]
First Name: [get_types_user_meta_custom id="[wpv-user field='ID']" key="first_name"]<br />

Standard WP fields do not use the wpcf- prefix in this context. You may need to check the Authors domain in String Translation for the appropriate slugs. Please let me know if this works for you.

#522485

Thank you so much, Christian, for your quick help!
That's the first step in the right direction. Your shortcode works for the custom user-meta! Yeah!

But unfortunately not for the standard-WP-user-fields. I tried it with two fields (my shortcodes name is "user-meta"):

[user-meta id="[wpv-user field='ID']" key="description"]
[user-meta id="[wpv-user field='ID']" key="user_lastname"]

But both didn't work. There my standard language "German" is placed instead of the translated content.

I already tried to unmark and remark the strings as "translation finished". Didn't work. So I deleted some of these strings and wanted to translate them again. But after deleting the strings they didn't come back for translation (wether in the domain "authors" nor in any other). For bringing back the strings, I already tried to:
* save the user with different inputs in these fields
* saved the view again, where these fields are shown
* unchecked and rechecked the role "editor" for translation
* unchecked and rechecked the domain "authors" for "auto-marking for translation"
* scanned the themes for strings

Nothing helped to bring back these strings. And all other remaining standard-WP-user-fields are still in my standard-language. Any ideas?

#522562

Hmm, the following code works for me:

User Last Name: [get_types_user_meta_custom id="[wpv-user field='ID']" key="last_name"]
User Bio: [get_types_user_meta_custom id="[wpv-user field='ID']" key="description"]

My translations appear as expected. If the strings do not reappear for translation after you delete and recreate them, it's possible that the field slugs have changed. You may need to update your wpml_translatable_user_meta_fields filter to reflect the new field slugs. Only be the custom fields need to be added, not the standard fields.

Can you let me know if updating the field slugs helps resolve the problem?

#522950

Hi Christian,
no, updating the field-slugs didn't help. The problem is not within the custom-user-fields – they are working now with your given shortcode. It's in the WP-standard-ones. And they don't have to be placed in the filter, am I right? Anyway, I tried both, placing the standard-fields in the filter and deleting them then again. Both didn't work.

But because these strings don't reappear in my string-translation-domain "Authors" when deleting them, I assume this problem is within WPML. I posted that on the WPML-thread and am waiting for a reply there. Please leave this issue open until the WPML-forum figured out, how to get those strings to reappear again. I'll be in touch with you then.

In the meanwhile: Thanks!

#523122

Okay let me know what you learn from the WPML side. Thanks!

#523728

Hi Christian!

We could solve the problem now: The standard-WP-user-fields have to be placed in the WPML-filter, too. It's a bit strange, that this didn't work the first time, when I tried to do this. But anyway, now it works perfectly.

After adding the standard-user-fields to the filter, these strings reappeared again for string-translation and they are marked as "translation has to be updated", whenever a field changes. And finally this did the trick for my Frontend also. Now both types of user-fields are translated in Frontend! So everything ist working fine now! Thanks!

For anyone, who landed here with the exact same problem. Here the steps for adding Types custom-user-fields to WPMLs string-translation:

1) Put this filter into functions.php and add ALL user-fields, which should be translated:

add_filter( 'wpml_translatable_user_meta_fields', 'add_usermeta', 99);
function add_usermeta( $fields ) {
    $fields = array('description','wpcf-my-custom-field');
    return $fields;
} 

2) Add the shortcode for displaying the user-fields in functions.php

add_shortcode( 'user-meta', 'user_meta_func');
function user_meta_func($atts) {
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

3) Add the shortcode in Toolset (Settings > Frontend > Shortcode-Arguments)
4) Add the shortcode wherever your fields should appear (in View, Layout, Page ...)

[user-meta id="[wpv-user field='ID']" key="description"]
[user-meta id="[wpv-user field='ID']" key="wpcf-my-custom-field"]

Thanks again, Christian, for your help!
You can mark this thread as solved now!
Best regards from Vienna, Diana

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.