Skip Navigation

[Resolved] Display field value in other language (WPML + PHP)

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

Problem:

The issue here is that the user wanted to render their custom field value using php. However with the function types_get_field_meta_value() it was rendering the field but not with the current language defined by WPML.

Solution:

I'm not aware of a types_get_field_meta_value() function to render the custom fields, however the correct function would be types_render_field()

This will allow the correct translations to be displayed as well.

I would recommend checking out the documentation for it as well.
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 5 years, 10 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by gianfrancoa 5 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1230952

I am trying to display the translation of my custom field value in a custom PHP function.
I'm using this function to get my values:

// get the post id and assign it to a variable
$post_id = get_the_ID();
//get the value from the field as it appears in the post with the ID from above and assign it to a variable
$fieldval = types_get_field_meta_value( 'your-field', $post_id );

I expected to see the translated value. Instead, I got the value in the default language

#1230989

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

Not sure where you go the function types_get_field_meta_value() from, however the correct function to use is this one here types_render_field()

In the link below you can see the example usage of this function.
https://toolset.com/documentation/customizing-sites-using-php/functions/

Please let me know if this helps.
Thanks,
Shane

#1230998

Hi, thank you, it's working using "types_render_field".
I've grabbed "types_get_field_meta_value" from another support topic in the forum here, but maybe it's an old topic 🙂

Thanks again 🙂

#1231001

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Happy I was able to assist you with this 🙂

If there are no further questions on this you can go ahead and mark this one as resolved so that other users can find this information.

Thanks,
Shane

#1231010

My issue is resolved now. Thank you!