Home › Toolset Professional Support › [Resolved] Display a default message in a view if multiple repeating fields are input
Problem:
I have a custom post type of "events". For each event I have a date field. Most events are single occurrences but some occur multiple times during a day, or on several days across a week for example - so I have this setup as a field that allow multiple instances.
I want to display these events in a compact view on my homepage. However, when there are multiple date entries, this can start to get quite untidy with long lists of dates for some events. What I would like to do in my VIew is the following:
• If the event only has one date instance, show it.
• If there is more than one date instance, do not show all the dates and instead show a default message like: "This event runs from [first date] on various dates. Please click for full details."
Solution:
I suggest you use Views shortcode [wpv-conditional] shortcode to check if the custom date has multiple instances, then display what you want, for example, the custom date field slug is "event-date":
[wpv-conditional if="'[wpv-post-field name="wpcf-event-date" index=1]' eq ''" evaluate="false"] This event runs from [types field='event-date' style='text' format='F j, Y' index=0][/types] on various dates. Please click for full details. [/wpv-conditional] [wpv-conditional if="'[wpv-post-field name="wpcf-event-date" index=1]' eq ''" evaluate="true"] If the event only has one date instance, show it. [types field='event-date' style='text' format='F j, Y' separator=', '][/types] [/wpv-conditional]
Please replace "event-date" with your custom date field slug
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
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 – 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)
Tagged: Views, Views plugin
This topic contains 3 replies, has 2 voices.
Last updated by Luo Yang 6 years, 10 months ago.
Assisted by: Luo Yang.
I have a custom post type of "events". For each event I have a date field. Most events are single occurrences but some occur multiple times during a day, or on several days across a week for example - so I have this setup as a field that allow multiple instances.
I want to display these events in a compact view on my homepage. However, when there are multiple date entries, this can start to get quite untidy with long lists of dates for some events. What I would like to do in my VIew is the following:
• If the event only has one date instance, show it.
• If there is more than one date instance, do not show all the dates and instead show a default message like: "This event runs from [first date] on various dates. Please click for full details."
Hi
I suggest you use Views shortcode [wpv-conditional] shortcode to check if the custom date has multiple instances, then display what you want, for example, the custom date field slug is "event-date":
[wpv-conditional if="'[wpv-post-field name="wpcf-event-date" index=1]' eq ''" evaluate="false"] This event runs from [types field='event-date' style='text' format='F j, Y' index=0][/types] on various dates. Please click for full details. [/wpv-conditional] [wpv-conditional if="'[wpv-post-field name="wpcf-event-date" index=1]' eq ''" evaluate="true"] If the event only has one date instance, show it. [types field='event-date' style='text' format='F j, Y' separator=', '][/types] [/wpv-conditional]
Please replace "event-date" with your custom date field slug
Thats worked perfectly - thanks
You are welcome.