Skip Navigation

[Resolved] Display Age from Date of birth with WPML

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 8 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2697795
invalid-tag-wpml.jpg

Tell us what you are trying to do?
I am using a code for displaying the age (only years) from a custom field with the date of birth.
It's working very well on my website.
The problem is, that I also use WPML and on the translated page it's not working due to the nested shortcode inside of the view.

The Custom Code:
add_shortcode( 'calculate_age', 'func_calculate_age_from_date_field');
function func_calculate_age_from_date_field($atts){
$age = 0;
extract( shortcode_atts( array(
'field' => '',
), $atts ) );

$age = floor( (time() - $field) /(365*24*60*60));
return $age;
}

The Code inside of the view:
[calculate_age field='[types field="geburtstag" output="raw"][/types]'

--> How to change the code inside of the view to make the code working on the translated page?
I tried to change it like this, but then I am causing a critical error (on translated page):
[format-date-difference start="geburtstag"][/format-date-difference]

I also tried the code mentioned in the following post:
https://toolset.com/forums/topic/calculate-age-according-to-custom-date-field-year-of-birth/
Like the first code it's working well on the website. But on pages translated with wpml it's not working anymore.

Is there any documentation that you are following?
https://toolset.com/forums/topic/display-age-from-date-of-birth-input/
https://toolset.com/forums/topic/calculate-age-according-to-custom-date-field-year-of-birth/

#2697800

Don't know if this is important, I am using the toolset legacy.

#2697874

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to translate the custom shortcode as per the following guide and try to resolve your issue:
- https://wpml.org/documentation/support/language-configuration-files/translate-custom-shortcodes-with-wpml/

#2698559

perfect! Thank you for this! My problem is solved