The times I’m trying to show are acf fields on an options page. Would that make a difference as to it working or not here?
Thanks for looking at this
<?php get_field(‘morning_start_time’); ?>
Was throwing up an error, because of php within php maybe? Went with
<?php
date_default_timezone_set('Europe/London'); // timezone
$weekday = date(l); // today
$now = new DateTime();
$morning = $now >= new DateTime(get_field('morning_start_time','option')) && $now <= new DateTime(get_field('morning_end_time','option'));
$afternoon = $now >= new DateTime(get_field('evening_start_time','option')) && $now <= new DateTime(get_field('evening_end_time','option'));
if($weekday == "Saturday" && ($morning || $afternoon)) : ?>
<h2>We're streaming</h2>
<?php else : ?>
<h2>No streaming</h2>
<?php endif; ?>
It doesn’t throw up an error but its also not working. Would that be because of the php date/time functions? My return format is H:i currently
Or is there an easier way to make this work? I just can’t work this out
So its setup so that content:
<h2>We’re streaming</h2>
Will show between the times –
$morning = $now >= new DateTime(’13:30′) && $now <= new DateTime(’13:40′);
$afternoon = $now >= new DateTime(’15:20′) && $now <= new DateTime(’15:45′);
Any other time it will show:
<h2>No streaming</h2>
Thanks so much
So would that be
$morning = $now >= new DateTime(‘<?php get_field(‘morning_start_time’); ?>’)
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.