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
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
My issue is resolved now. Thank you!