• Hi there,

    I’d like to perform different queries for a post archive depending on the age of the post.

    If the post has been written within the last 60 days:

    Do this ########

    Else

    Do this ********

    So I need to have the date of when the post was written with get_the_time and then see if its been written within the last 60 days.

    Do you know how to do this? And could you show me how here? ??

    Many thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Here is some code I found a while back (modified to work for you). It just has to be used within the loop of course.

    <?php
    global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = (( time() - mktime('','','', $postd[1], $postd[2], $postd[0])));
    $days_old = floor($ageunix/(24*60*60));
    
    if ($days_old <= 60) {
      // do this
    } else {
      // do this
    }
    
    ?>
    Thread Starter honewatson

    (@honewatson)

    awesome thanks man!

    Thread Starter honewatson

    (@honewatson)

    I got this error:

    “mktime() expects parameter 1 to be long”

    This worked better for me in the loop:

    <?php $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    ?>
    
    <?php if ($days_old > 60) : ?>
    
    <?php else : ?>
    
    <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If Post is Older than 60 days do this…’ is closed to new replies.