Home › Toolset Professional Support › [Resolved] Help with writing a conditional to hide a section of text
Problem:
The issue here is that the user wanted assistance to compare 2 Toolset Types date fields and hide a section of their content if both date fields are equal.
Solution:
It should be noted that Toolset date fields are stored as timestamps so this will be an exact comparison depending on the precision of the date field. What I mean is that if you set the field to datetime then the dates and the times of both fields must match exactly.
Once you can confirm this then you will be able to compare them below using the timestamp.
[wpv-conditional if="( $(date-aa) eq $(date-bb) )"] <!-- content to conditionally show goes here --> [/wpv-conditional]
Should it be a case where the fields have the same date but different times then you can use the format below.
[php]This will do a comparison based on the human readable date only.
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)
This topic contains 2 replies, has 2 voices.
Last updated by chantalM 3 years, 5 months ago.
Assisted by: Shane.
Hi there,
I have a view which displays the following:
[types field="date-aa" format="D d M "][/types] - [types field="date-bb" format="D d M Y"][/types]
If 'date-aa' is equal to 'date-bb', I would like that whole section to be hidden from display.
I am unsure how to write the conditional... (I don't use blocks)
What do I need to put round this text please to ensure this section is hidden if the two dates are the same?
Thank you so much.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Bear in mind that date fields are stored as timestamps (the number of seconds since 1 Jan 1970). Will the field values (in seconds) be exactly equal?
If so then you can test the raw values of the fields, like so:
[wpv-conditional if="( $(date-aa) eq $(date-bb) )"] <!-- content to conditionally show goes here --> [/wpv-conditional]
If they may not be exactly the same (e.g. they refer to different times on the same day) then you would have to use formatted dates generated by types shortcodes, being sure to use the same format, so something like:
[wpv-conditional if="( '[types field='date-aa' format='Y m j'][/types]' eq '[types field='date-bb' format='Y m j'][/types]' )"] <!-- content to conditionally show goes here --> [/wpv-conditional]
My issue is resolved now. Thank you!