Skip Navigation

[Resolved] Conditional date output

This support ticket is created 4 years, 11 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
- 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 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1668619

Tell us what you are trying to do?
Display start date if one-day event and more if additional days scheduled. Basically I only need start date if not more than one day but would like additional of more than one - i.e. Jan 1 (one day only) OR Jan 1 to Jan 3 (3-day event)

Is there a similar example that we can see?
[wpv-conditional if="( $(wpcf-start-date) eq '$(wpcf-end-date)' )"][types field="start_date"][/types][/wpv-conditional]
[wpv-conditional if="( $(wpcf-start-date) ne '$(wpcf-end-date)' )"] to [types field="end_date"][/types] [/wpv-conditional]

#1669231

Hello,

It needs custom codes, for example:
1) Add below PHP codes into your theme file "functions.php":

add_shortcode('days', function($atts, $content){
	$start_date = get_post_meta(get_the_ID(), 'wpcf-start-date', true);
	$end_date = get_post_meta(get_the_ID(), 'wpcf-end-date', true);
	$res = ($end_date - $start_date) / (3600 * 24);
	return round($res);
});

2) Use above custom shortcode like this:

[wpv-conditional if="( $(wpcf-start-date) eq '$(wpcf-end-date)' )"][types field="start-date"][/types](One day event)[/wpv-conditional]
[wpv-conditional if="( $(wpcf-start-date) ne '$(wpcf-end-date)' )"][types field="start-date"][/types] to [types field="end-date"][/types]([days] days event)[/wpv-conditional]

Please replace "start-date" and "end-date" with your custom date field slugs.