Expire the old posts

WordPress Plugin Post Expirator

How to create WordPress plugin Post Expirator. The post expire after 10 days


Copy the code below in functions.php

/*** Expire the old posts 10 days **/
function expire_post () {
global $wpdb;
$daystogo = "10";
$sql =
"DELETE FROM {$wpdb->posts}
WHERE DATEDIFF(NOW(), post_date) > %d AND
post_type = 'post' AND
(post_status = 'publish' OR post_status = 'pending' OR post_status = 'inherit')";
$wpdb->query($wpdb->prepare($sql, $daystogo));
add_action('wp_head', 'expire_post');
add_action('admin_head', 'expire_post');

Leave a Reply

Your email address will not be published. Required fields are marked *