Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Wordpress Post Expirator
This function assumes a custom field named 'expiration' with a human friendly date/time.
function is_post_expired($post_ID = null){
if(!$post_ID) global $post;
$post_ID = $post_ID ? $post_ID : $post->ID;
//Human Friendly Expiration Date
$expiration = get_post_meta($post_ID, 'expiration', true);
//Adjust server time for your timezone
$expiration_timestamp = strtotime($expiration);
$time_left = $expiration_timestamp - time();
if($time_left < 0):
return true;
function expire_post($post_ID){
$args = array(
'ID' => $post_ID,
'post_status' => 'draft'
return true;

This comment has been minimized.

Copy link

@covoiturage covoiturage commented Aug 23, 2013

Hello everyone,

first thanks so much for sharing this code. I am using the theme Classipress with the child theme Eldorado and just want to know where to insert this php file; into the parent theme or into the child theme. Another question: how to set the custom field "expiration" ?

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment