Skip Navigation

[Résolu] How to show futures dates – each on one line?

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.

This topic contains 2 réponses, has 2 voix.

Last updated by fred-r.M Il y a 4 mois et 1 semaine.

Assigned support staff: Waqar.

Auteur
Publications
#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: Anglais (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!