Problem: I would like to display a User's age based on a custom date field that stores their birthdate.
Solution: Use the following custom shortcode:
add_shortcode( 'time_ago', 'time_ago_func'); function time_ago_func($atts){ global $wpdb; extract( shortcode_atts( array( 'birthdate' => '', ), $atts ) ); // handle the case where birthdate field is not set if( !$birthdate ) { return ''; } $age = floor((time() - $birthdate)/(365*24*60*60)); return $age; }
Use the following syntax to display the User's age:
[time_ago birthdate='[types usermeta="nanny-date-of-birth" raw="true" user_current="true"][/types]'] years old
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 |
---|---|---|---|---|---|---|
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 5 replies, has 2 voices.
Last updated by 5 years, 2 months ago.
Assisted by: Christian Cox.