Skip Navigation

[Resolved] Calculating fields

This support ticket is created 6 years, 9 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.

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
- 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 15 replies, has 3 voices.

Last updated by Luo Yang 6 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#558417

Dear jianfengZ,

I just got this thread, for you question:
User needs to select date of birth of self using date picker, can I output how old the user is as far? and if possible, can I use a filter by age range and display results after stored the post?
There isn't such a built-in feature within Toolset, I suggest you try these:
1) Create two custom fields:
a) Custom date field, for example "birthday"
b) Custom numeric field, for example "age"

2) Create a CRED form of your user to fill the "birthday" field value

3) When user submit above CRED form, use CRED action hook "cred_save_data" to trigger a custom PHP function,
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
in this PHP function do these:
a) Get the field value of "birthday"
https://codex.wordpress.org/Function_Reference/get_post_meta
b) Use "birthday" value to calculate the "age" value, and put it into field "age"
https://codex.wordpress.org/Function_Reference/update_post_meta
4) Then you will be able to output the custom field value of age, and order the view by the "age"

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