Skip Navigation

[Resolved] MONTHS_FROM_NOW() not working in condition

This thread is resolved. Here is a description of the problem and solution.

Problem: I am trying to create a conditional that tests if a custom date field is between TODAY() and MONTHS_FROM_NOW(2), but it's not working as expected. A date one month from now is hidden by the conditional.

Solution: Use the following format with no line breaks and enclosing parentheses around both clauses:

[wpv-conditional if="(( $(wpcf-rental_end) gt 'TODAY()' ) AND ( $(wpcf-rental_end) lt 'MONTHS_FROM_NOW(2)' ))"]Condition is true[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

This support ticket is created 3 years, 10 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
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)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by nabils 3 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1672285

Tell us what you are trying to do?
In the view I have some row with end date is more than one day and less than 2 months. This rows I want to make in different color therefore I have used the condition below.

[wpv-conditional if="( $(wpcf-rental_end) gt 'TODAY()' )
 AND 
( $(wpcf-rental_end) lt 'MONTHS FROM NOW(2)' )"]

The TODAY() is working but MONTHS FROM NOW(2) is not working.
What can be the problem?

#1672597

Hello, a couple of things:
- What about MONTHS_FROM_NOW(2) with underscores?
- What is the exact value of wpcf-rental_end in this case?

#1672639

Hi,
As correction for the previous explanation, end of rent date (rental_end) is more than today and less than 2 months. An example of rental_end is 31/7/2020.

#1673563

You should use underscores between the words MONTHS_FROM_NOW, you should not include any line breaks, and you should enclose everything in another set of parenthesis like this:

[wpv-conditional if="(( $(wpcf-rental_end) gt 'TODAY()' ) AND ( $(wpcf-rental_end) lt 'MONTHS_FROM_NOW(2)' ))"]Condition is true[/wpv-conditional]

If this isn't working, please turn on debug mode and tell me what is displayed on the front-end:

[wpv-conditional if="(( $(wpcf-rental_end) gt 'TODAY()' ) AND ( $(wpcf-rental_end) lt 'MONTHS_FROM_NOW(2)' ))" debug="true"]Condition is true[/wpv-conditional]
#1674765

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.