Skip Navigation

[Resolved] How to get value of users custom field which is date type

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
- 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 4 replies, has 2 voices.

Last updated by Ankit Katailiha 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2412301

Hi Team,
I have created a custom field for users, which is DATE type. I have tried retrieving that custom field value by -
$recent_working_month = 'recent-working-day-month';
$recent_working_month_value = get_user_meta( $user_id, $recent_working_month, true );

but this code is not working and I'm not getting the Date value. Please guide me how can I get the Date custom field value.

#2412323

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

All custom fields created using Types plugin will have 'wpcf-' prefix.

Could you please try to use the following code:

$recent_working_month = 'wpcf-recent-working-day-month';
$recent_working_month_value = get_user_meta( $user_id, $recent_working_month, true );

This should work. Happy Coding 🙂

#2412347

Thanks! but the date in the database is "20 June 2022" and the value I'm getting from above code id "1655683200". I didn't understand. Does it need any conversion?

#2412349

Minesh
Supporter

Languages: English (English )

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

Types stores custom date field value to database as Unix timestamp. You will have to convert this Unix Timestamp to readable date using PHP date funciton.

Or

You can use Types Field's API function:
- https://toolset.com/documentation/customizing-sites-using-php/functions/#date

For example:

echo types_render_usermeta( "recent-working-day-month",array('user_id'=>$user_id));

This should print the formatted date. To change the format, you can use the 'format' attribute, see above doc.

#2412361

My issue is resolved now. Thank you!

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