Skip Navigation

[Resolved] Show future dates only with multiple instance custom field Date

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 4 replies, has 2 voices.

Last updated by marcellinoB 9 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#290312
2015-03-18_23-04-17.jpg

I am trying to: Show/include only future dates from a multiple instance custom field "Date' within a View. [types field="workshop-data-start" style="text" format="d/m/Y" separator="<br/>"][/types]. So a for-each and if-evaluate needs to show the Dates that are > (greater than) the current date/time. I believe the evaluate needs to perform a comparison based on timestamp value ( time() ).

I visited this URL: https://toolset.com/forums/topic/date-field-multiple-instances-show-only-today-or-higher/

I expected to see: The above topic mentions some issues with processing code in a certain order, so using this code example doesn't do the job.

Instead, I got: Tried some alternatives, but don't seem to get any results. The View displays properly but the for-each and if-evaluate returns 'empty'. In the attached screenshot is the View displayed. There is a date shown (12/03/2015) in the second row. This date shouldn't be shown based on the current date of 18/03/2015.

#290321

The problem is the for-each statement, which doesn't seems to execute together with the if statement.

Below code works partially. When the dates are all in the future, they show. When there is a date in the Date instances that is in the past, the for-each stops working.

[wpv-for-each field="wpcf-workshop-data-start"]
[wpv-if expiration="wpcf-workshop-data-start" evaluate="$expiration > '[today_date]'"]
[types field="workshop-data-start" style="text" format="d/m/Y"][/types]
[/wpv-if]
[/wpv-for-each]

#290324

Ok, i see at this URL: https://toolset.com/documentation/views-shortcodes/#wpv-for-each

Note: wpv-if shortcode won’t work inside a wpv-for-each shortcode

So, it isn't supposed to work anyway in the current code.

Is there a work-around or is it just not possible?

Would be great if this could be added to the existing code. Let's you create a lot of additional/conditional Views with multiple instance values.

#290406

Yes, you are right, as the document mentioned wpv-if shortcode won’t work inside a wpv-for-each shortcode
https://toolset.com/documentation/views-shortcodes/#wpv-for-each

In your case, I suggest you try create a custom shortcode for it, for example:
1) add below codes in your theme functions.php:

add_shortcode('my-repeating-dates', 'my_repeating_dates_func');
function my_repeating_dates_func($atts, $content){

    extract(  shortcode_atts( array(
		'field' => '',
		'strtotime' => 'Today',
		'style' => 'text',
		'format' => 'd/m/Y',
		'separator' => ', ',
	), $atts ));
	$res_arr = array();
	$arr = get_post_meta(get_the_ID(), $field, false);
	$value = strtotime($strtotime);
	foreach($arr as $k=> $v){
		if($v > $value){
			$res_arr[] = date_i18n( $format, $v);
		}
	}
	$res = implode($separator, $res_arr);
	return $res;
} 

2) use below above shortcodes in your content, like this:
[my-repeating-dates field="wpcf-workshop-data-start" strtotime="Today" style="text" format="d/m/Y" separator=", "]

#290459

Luoy,

Works like a charm. Would be cool if there could be a bunch of ready-made functions like this available which you can use out-of-the-box.

This code snippet is a great starting point for solving more things like this.

Thank you very much for support!

Marcellino

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.