Support » Fixing WordPress » How do I check if a post was published later than a certain date?

  • I know how to check the age of a post, relative to today’s date, but now I would like to check if a post was published after a particular date.

    For example, say the cutoff date is 08/05/11, I need to be able to check if the post that is displaying on the page was posted later than 08/05/11.

    Anyone know how to do this? I know the template tag is get_the_date(), but I just don’t know how to do the date manipulation.


Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php if (strtotime($post->post_date) > strtotime('-4 days')): ?> <b>NEW</b> <?php endif; ?>

    Taken from

    PHPs strtotime function parses just about any English textual datetime description into a Unix time-stamp that can then be compared, so today’s date would be something like 1234 and yesterdays date is 1233 so you can use the code above to do your comparisons.

    More Info:

    That’s great. Thanks!!!

    I’m having a problem get the post date to work with the into strtotime() function.

    global $post;
         $post_secs = strtotime($post->post_date);

    That does not put any value into $post_secs. I first had it without the global $post and then tried adding it.

    I’m using this in a custom_functions function in Thesis.

    I also just tried use the_date() and get_the_date() with no luck.

    Okay, this interesting. I use EXEC PHP plugin so I can run PHP in a WP page. So I put the following into a page, and viola!, it grabbed the post date with get_the_date().

    $this_post_date = get_the_date() ;
    $post_secs = strtotime($this_post_date);
    $cutoff_secs = strtotime('March 01 2009');
    echo $cutoff_secs;
    echo $post_secs;

    However, when I place this code in the Thesis custom_functions file, the $post_secs is blank. I tried adding a global $post at the beginning, but the same thing happens.

    I’m so close, can someone tell me how to make it work in custom_functions? This doesn’t make any sense to me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I check if a post was published later than a certain date?’ is closed to new replies.