This thread is resolved. Here is a description of the problem and solution.
Problem:
How to translate and display user custom fields created with Toolset types.
Solution:
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"]
Relevant Documentation:
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: String Translation, Toolset - WPML
Related documentation:
This topic contains 22 replies, has 2 voices.
Last updated by Yvette 3 years, 8 months ago.
Assigned support staff: Yvette.
Author | Posts |
---|---|
April 27, 2017 at 6:21 pm #1263732 | |
Diana |
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 But the Frontend shows all the user-infos in my standard-language German, instead of English. I already tried to: * "Scan themes for strings" in WPMLs theme- and plugin-localization 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 a trick to that? Or do I miss something? |
April 28, 2017 at 7:49 am #1264044 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
Hello I´ll be helping you with this issue. 1. Could you post the code that you added to your functions.php here? 2. Clarification 3. Technical Information on you environment Thank you. |
April 28, 2017 at 9:41 am #1264133 | |
Diana |
Hi Yvette! 1. Here's the code I've added to functions.php: 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; } ); 2. Yes, both of them aren't showing up, both of them are in standard-language. And I have two separate views, which are showing different layouts for the user-information. And on both views, they are in standard language. 3. Did so now. 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] In my screenshot you can see, that the strings are translated and marked as finished. Thanks for your help! |
April 28, 2017 at 2:23 pm #1264387 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
1. Retrieving the user meta. get_the_author_meta( 'user_url', $user_id ); 2. Could you also post the code that you use in your "views"? I would like to get some consultation from our 2nd tier supporters. thank you. |
April 28, 2017 at 4:42 pm #1264507 | |
Diana |
1. No, I'm not using this code, because I'm not working with my own php-page-templates. Instead I'm working with Toolset Layouts and Views. And the shortcode 2. Here the loop-code of one of my Toolset-Views-Templates: [wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <wpv-loop> <div id="[wpv-user field='user_firstname']" class="person"> <div class="visitbild"> [types usermeta="portraet-bild"][/types] </div> <div class="visitdaten"> <h4>[wpv-user field="user_firstname"] <b>[wpv-user field="user_lastname"]</b> <span>[types usermeta="team-titel"][/types]</span></h4> <p>[types usermeta="team-pos"][/types]</p> <div class="icons"> <script type="text/javascript">javascript:contactteam('[wpv-user field="user_firstname"].[wpv-user field="user_lastname"]','next-pm.at');</script> <a href="<em><u>hidden link</u></em> field='user_firstname'][wpv-user field='user_lastname'].vcf" rel="external" alt="vCard zum Download"> <div class="vcard"></div> </a> </div> <h5>[types usermeta="team-aufgaben"][/types]</h5> <p>[types usermeta="team-ausbildung"][/types]</p> </div> <div class="no-mobile visitbeschr">[wpv-noautop][wpv-user field="description"][/wpv-noautop]</div> </div> </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-layout-end] But the View works, so I don't think it's in this code. I also tried to add other content in the same View (for instance another Content-Template) and this shows up with the translated content. And because even the standard-user-fields aren't in English I think, there is more to do for getting the translated user-fields to work. |
April 28, 2017 at 4:47 pm #1264511 | |
Diana |
If I have to place the above code to get this working, where should I do that? |
April 28, 2017 at 4:53 pm #1264516 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
I´m consulting with a colleague, please be patient - they may have already left for the weekend. = ( |
May 1, 2017 at 5:10 pm #1265622 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
Hello. Can you please provide access to your system. I think I will need to hand this over to someone more experienced with Toolset programming. Thank you. |
May 3, 2017 at 7:21 am #1266840 | |
Diana |
I'm developing on localhost and don't have an online-account yet for this project. May I give you a backup of my site? I'm working with UpdraftPlus and could provide you a clone of my development. It's about 350 MB at the moment ... |
May 3, 2017 at 4:31 pm #1267406 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
1. System Snapshot The plugin is free and is easy to use. Here is an instructional video. 2. String domain 2.1 Can you check if the user fields are enabled for translation in WPML String Translation and maybe try re-saving them? 3. Private area Thanks! |
May 4, 2017 at 6:33 pm #1268555 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
Hello again. Thanks for doing this. I´ve been doing some research on the "other side of the house" and I found this ticket: https://toolset.com/forums/topic/wpml-cant-translate-added-user-fields-content/ The date is Sept 2016 and I fear that this may imply that WPML cannot yet be used to translate these fields "as is". I am double-checking this with our 2nd tier support as well as if there is a documented workaround. But I thought I´d raise this flag for your consideration. You might also ask on the Toolset forum for their inputs. (never hurts). |
May 5, 2017 at 10:00 am #1269035 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
Hello. Thanks for your ongoing patience. I have escalated this issue to our 2nd tier support who will be able to help you get a definitive answer and hopefully a workaround. Kind regards. |
May 9, 2017 at 11:05 am #1271609 | |
Diana |
Hi Yvette! I searched on the Toolset-Forum and I checked out the link you gave me. You are right, the post is from Sep 16, but since then WPML and Toolset changed a few things. Now it is possible to translate the strings by adding the user-role in the string-translation-settings-page. They all appear in the domain "authors" (they didn't when the sep16-post was written). So now it should be possible to implement the translated content in my Views. There should be a shortcode for that. Otherwise the setting in WPML to add a role for translation, wouldn't make sense. Would it? |
May 9, 2017 at 2:01 pm #1271835 | |
Yvette Supporter
Languages: English (English ) Spanish (Español ) Timezone: America/Los_Angeles (GMT-08:00) |
Hello again. Every WP default meta is translatable via ST if you go to ST > bottom right > activate translation for this roles... HOWEVER.... I have confirmation from the development team that this is not yet a supported feature. You are right - it makes no sense imho. I´ve added your ticket to the growing list of votes that this support be added. It´s the most I can do for now. To return to your original quest, that would suggest that the only way to get these fields would be via get_the_author_meta( 'user_url', $user_i Your thoughts? |
May 9, 2017 at 4:30 pm #1271987 | |
Diana |
Hi again! So that isn't a supported feature as well for the WP-default-user-fields? Or in which way do I have to include the fields in my Views. Which shortcode does the trick for these fields? |