If you made your special offers a custom post type you could set the ‘scheduled’ date to the day you wanted it to expire then use this code to auto publish it on schedule after you’ve changed the scheduled date. The ‘future_show’ line goes with my ‘show’ custom post type so if you had a ‘deal’ custom post type it would say ‘future_deal’.
<?php
function sfn_setup_future_hook() {
// Replace native future_post function with replacement
remove_action('future_show','_future_post_hook');
add_action('future_show','publish_future_post_now');
}
function publish_future_post_now($id) {
wp_publish_post($id);
}
add_action('init', 'sfn_setup_future_hook');
?>
You can then set the post to expire if it’s older than today on the server with the code below. It hooks into WordPress cron so you’re not running it all the time but you’ll notice a line commented out that runs it on init so you can test it. For testing comment out the first 3 lines and use the init action. Don’t do this on production though.
<?php
// setting posts with current date or older to draft
if (!wp_next_scheduled('sfn_expire_hook')){
wp_schedule_event( time(), 'hourly', 'sfn_expire_hook');
}
add_action( 'sfn_expire_hook', 'sfn_show_expire');
function sfn_show_expire(){
global $wpdb;
$server_time = date('mdy');
$result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type="show" AND post_status="publish"");
if( !empty($result)) foreach ($result as $a){
$show_time = get_the_time('mdy', $a->ID);
if ( $server_time > $show_time ){
$my_post = array();
$my_post['ID'] = $a->ID;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
}
} // end foreach
}
// add_action( 'init', 'sfn_show_expire' );
?>
Don’t forget to change my function prefix (sfn) to your own just to sandbox it’s function from anything else.
Edit I just also thought that you could change the SQL query to grab posts in a category of ‘deal’ and it would work the same way. Creating an entire post type then including it in the site/blog may be more work than is needed.