I have an events field for my homepage. There is a WYSIWYG field called calendar_item and a Date Picker field called time_expiry.
I would like to compare today’s date against time_expiry and if time_expiry is greater, show calendar_item.
This code seems like it should work, but I’m not getting any results when I view the page. Any idea what I’m missing?
<?php date_default_timezone_set('America/New_York'); // set default timezone
$today = date('Ymd'); // get today's date
$expire = the_sub_field('time_expiry', 'option'); //get ACF expiration date
$event = the_sub_field('calendar_item', 'option'); // This is our announcement field
if ( have_rows( 'calendar' ) ) : while ( have_rows( 'calendar' ) ) : the_row();
if( $expire > $today ) : //Is time_expiry greater than todays date?>
<?php echo $event; // echo the event?>
<?php endif; endwhile; else : endif;?>
Is there another have_rows() loop before you try to get the sub fields ‘time_expiry’ and ‘calendar_item’? or are these sub field of ‘calendar’? Is ‘calendar’ from ‘option’ as well or from a post?
Also, to get the value of a field you need to use ‘get_sub_field()and not
the_sub_field()` since the second function echo the value and does not return anything.
thanks for the information...