Skip to content

Instantly share code, notes, and snippets.

@hissy
Created June 13, 2012 03:21
Show Gist options
  • Save hissy/2921625 to your computer and use it in GitHub Desktop.
Save hissy/2921625 to your computer and use it in GitHub Desktop.
check the post is recently posted #WordPress
/**
* Usage: if ( is_new() ) : echo 'NEW!'; endif;
* you can check if the post was posted within 30 days.
*/
function is_new($day=30,$post=null){
$term = $day * 24 * 60 * 60;
$post = get_post($post);
if ( !$post || is_wp_error( $post ) )
return false;
$the_time = $post->post_date;
$time = strtotime($the_time);
$compare_time = time() - $term;
if($time > $compare_time){
return true;
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment