Home / date / Post is older than
  • How to Post is older than

    no thumbnail sorry: Post is older than

    Adding this first block of code to your functions.php will allow you to check the age of a post to see if it is older than a set number of days. Great if you want to display some some information related to the post after set number of days or even stop displaying the post altogether.

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    <>
       function is_old_post($days = 5) {
           $days = (int) $days;
           $offset = $days*60*60*24;
           if ( get_post_time() < date('U') - $offset )
                return true;
           return false;
        }
    
    ( click code to copy )

    wordpress snippet : PHP - loop

    <>
        if ( is_old_post(10) ) {
          // do something if the post is old
          } else {
          // do something if the post is not old
        }
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_post,
  • thanks, using this on my site.

  • Pete Petersen

    Awesome, thanks! What would be the best way to translate this function
    into hours instead of days? I tried simply removing the *24 from the equation, but this did not provide accurate results.