Home Forums Front-end Issues Hide Passed Dates Reply To: Hide Passed Dates

  • Hi.

    You will need to check the values of each date and compare it with the current date.

    First, declare a variable with the current unix time before you run through all the date checks.

    $now = time();

    This will save the unix time stamp which is a long number that makes no sense until converted into a human readable format. Basically, its the number of seconds from the UNIX epoch, or January 1st, 1970.

    This value will automatically update everytime the function is called of course.

    Now, between each check if a value exists for a key, don’t immediately print the field value with the_field(‘key’) function. Instead, compare it now to the $now variable you just declared. Compare it like this:

    $date_one_timestamp = strtotime(get_field('date_one));
    if ($now < $date_one_timestamp ) {
    // Since the the date is ahead of the absolute second of now
    // we will echo the timestamp using the date function, and format it like
    // "January 20, 2014"
    echo date("F j, Y", $date_one_timestamp);
    } else {
    // do nothing or do something else
    // because the unix time stamp of the date is greater then this second in time

    Now, this assumes that for the date field in ACF, you saved it using a format that can be read by the php strtotime function. More on that can be read here:

    But as you will read, the best way to format it is YYYY-MM-DD
    Since that will keep from ambiguity when its trying to figure out what each numbers mean.

    Hope that helps.

    Last bit, for more efficient code and presentation for yourself/clients when delcaring these dates, consider purchasing the Repeater Field addon. Then again, @elliot is about to turn all addons into a complete ACF Pro plugin, so maybe hold off too. Repeater addon is great, as is the rest of the addons.

    Btw, I don’t work for Elliot, just helping out. This is seriously the best plugin available for WP and powers 2 of my projects that I have highly customized.