Created
October 12, 2013 15:31
-
-
Save jentanbernardus/6951289 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( is_old_post(10) ) { | |
// do something if the post is old | |
} else { | |
// do something if the post is not old | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment