Problem:
I have a CPT that include 2 dates, one start date, one end-date.
Displaying the output is pretty simple and easy, but I would love to do this :
IF month from start_date is different month from end_date, do something
IF month from start_date is equal month from end_date, do something else
So i think I first need to get the data out of the date fields to be able to compare the month and that is where I am stuck
Solution:
You can use Types shortcode to output the month value of custom date field by setting the "format" attribute, for example:
[types field="start_date" format="m"][/types]
[types field="end_date" format="m"][/types]
https://toolset.com/documentation/customizing-sites-using-php/functions/#date
format:
any valid WordPress date format
Then you can use them in the Views shortcode [wpv-conditional] to check if the month values are equal, for example:
[wpv-conditional if="( '[types field="start_date" format="m"][/types]' eq '[types field="end_date" format="m"][/types]' )"] do something [/wpv-conditional] [wpv-conditional if="( '[types field="start_date" format="m"][/types]' eq '[types field="end_date" format="m"][/types]' )" evaluate="false"] do something else [/wpv-conditional]
Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
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 3 réponses, has 2 voix.
Last updated by Luo Yang Il y a 6 années et 3 mois.
Assisted by: Luo Yang.