Skip Navigation

[Resolved] Changing a Date type for Custom field to Single Text

This support ticket is created 5 years, 7 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Mukesh 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1260653

Tell us what you are trying to do?
My client is asking me to change two custom fields type. Currently they are Field Type of Date. Now they want to make it a so that they can type in the date instead of Selecting it using DatePicker. I'm thinking that converting the Custom Fields to Type of Single Text will allow them to enter date manually. What advice or suggestion do you have and are their any drawbacks with converting Date to Single Field that I should consider and keep in mind? Are their any other options to leave the fields as Date Field Type but also allow user to manually enter the date?

#1260755

Hello,

The custom date field created by Types will stores value in Timestamp format, I don't think it is good idea: change it to single line field, ordinary user won't be able to input the correct timestamp value.

For the question:
Are their any other options to leave the fields as Date Field Type but also allow user to manually enter the date?

There isn't such a built-in feature within Toolset Types plugin, you might consider custom codes, for example:
1) Create another custom single line field "my-date-2"
2) After user input the date value into above single line field, and save the post, use action hook save_post to trigger a PHP function,
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
Get the value of single line field "my-date-2", turn it into timestamp format, and save it into your custom date field.

For your reference.

#1262591

Thanks Luo.

So what if we do this...
1) Convert the Date field to Single Line (not create a new one).
2) Hook into the cred_submit_complete Action and convert the inputed date to timestamp and store it?

This would do similar to your suggestion but avoid creating a new field. When I display the date I will convert back to proper formatted date.

Thanks,
Mukesh

#1262669

Hi Luo, after thinking through the solutions I think the option you provide or creating a second field and then behind the scenes updating the existing Date field is probably the best option. If I had converted the existing Date field to Single Line, then I would have had to update every View and Form to format the display and that would be a lot of time. With your option I just need to update the Forms where I ask for Date of Birth and create the Hook function to update the Date field then all the views and forms stay in tact.

Thanks for the solution.

#1262671

My issue is resolved now. Thank you!