Skip Navigation

[Resolved] How to show futures dates – each on one line?

This support ticket is created 2 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.

Our next available supporter will start replying to tickets in about 1.98 hours from now. 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by fred-r.M 2 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1990225

Tell us what you are trying to do? I have a custom field as typ of date and multiple instances are able to use.

Now I like to show futured dates - from the current dates on - each date on one line...

Is there any documentation that you are following?

Is there a similar example that we can see?

hidden link - under "TourDates"

Right now it just shows me: 18. January 2021, 15. January 2021, 17. February 2021, 25. February 2021

My code is like this - I just should compare the current date with all the dates - and showing only those are in the future.

function get_featured_dates() {

global $post;
$str = '';
$tourdates = get_post_meta($post->ID, 'wpcf-start-tour-date', false);
$alltourdates = count($tourdates);
$mycounter = 0;
while ($mycounter < $alltourdates)
{
$myresults = date( 'd. F Y', $tourdates[$mycounter]);
$mycounter++;
/*$str .= $mycounter;*/
$str .= $myresults.'<br>';
}
return $str;
}
add_shortcode( 'show_featured_dates', 'get_featured_dates' );

What is the link to your site?

hidden link

#1990393

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To make sure your shortcode returns only the future dates from the custom field, you can update it to:


function get_featured_dates() {

global $post;
$str = '';
$tourdates = get_post_meta($post->ID, 'wpcf-start-tour-date', false);
$alltourdates = count($tourdates);
$today = strtotime('today midnight');
$mycounter = 0;
while ($mycounter < $alltourdates)
{
	if($today < $tourdates[$mycounter]) {
		$myresults = date( 'd. F Y', $tourdates[$mycounter]);
		$str .= $myresults.'<br>';
	}
$mycounter++;

}
return $str;
}
add_shortcode( 'show_featured_dates', 'get_featured_dates' );

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1992031

My issue is resolved now. Thank you!

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