WordPress.org

Forums

The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

if custom field is older than date next week (2 posts)

  1. robparker
    Member
    Posted 3 years ago #

    I'm trying to find a way to query on single.php if a post custom field (a date) is greater than a date 7 days in the future.

    <?php
    $date1 = get_post_meta($post->ID, '_timestamp', true);
    $date2 = date('YmdHi', strtotime($date .' +7 day'));
    if ( $date1 > $date2 ) { ?>

    The idea is to be able to filter those posts coming up in the new 7 days and those that are not. Custom field _timestamp outputs the date as YmdHi, so I've done the same with the date function.

    Something doesn't seem to be right though, and I'd appreciate any help with this.

  2. Slobodan Kustrimovic
    Member
    Posted 3 years ago #

    Try this...

    $date2 = date('YmdHi', strtotime('+7 day', $date));

Topic Closed

This topic has been closed to new replies.

About this Topic