Skip Navigation

[Resolved] Add condition based on date and number fields

This support ticket is created 4 years 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Shane 4 years ago.

Assisted by: Shane.

Author
Posts
#1592697

Hi,
Tell us what you are trying to do?
I have a date field called start date and number field called renew_days. I want to make condition to display a button if today is after days from the start date display the button. (start date + renew_ days <today). Please advise me how this can be done?

#1592943

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

Thank you for getting in touch.

This number field. What exactly is stored in there?

Is it a timestamp of the date? Could you send me a screenshot of this number field with some example data in there?

Thanks,
Shane

#1593127

The user can enter any number. For example if the user entered 5 this means five days after the start date.

#1593133
renew days.png

Please see the screenshot attached.

#1593161

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

I understand your issue now.

For this you will need to write some amount of custom code to achieve. That is because we do not have any mechanism in our plugin to add lets say 5 to a date field.

What you will need to do is to write the custom code that can add the 5 to the date and then return a timestamp that can be compared to today. You will also need to write some custom code to get today's date for a comparison.

I would suggest having a look at this link below to show you how you can add to a date .
https://stackoverflow.com/questions/3727615/adding-days-to-date-in-php

You can also use this tool below to generate your custom shortcode for you to pass into our conditional shortcode.
hidden link

Finally to get the field values from the database directly you can use the functions in the link below.
https://developer.wordpress.org/reference/functions/get_post_meta/

So in summary you will need to do the following.

1. Get the value of the date field and the number of days to be added with the custom shortcode
2. Within that same shortcode you will need to add the dates together to get a final date and return it as a timestamp
3. Create a 2nd shortcode that would get today's date as a Timestamp.
4. Use our conditional code to compare both timestamps to display your data.

Unfortunately because this involves custom coding to achieve I'm unable to assist with the writing of the code. For assistance like this I would highly recommend getting in touch with a contractor that has these expertise.
https://toolset.com/contractors/

Thanks,
Shane

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