Skip to content

Instantly share code, notes, and snippets.

@shahzaibkhan
Created July 21, 2022 15:28
Show Gist options
  • Save shahzaibkhan/5c1c79cf51da9841ddb98be83b6a7b5c to your computer and use it in GitHub Desktop.
Save shahzaibkhan/5c1c79cf51da9841ddb98be83b6a7b5c to your computer and use it in GitHub Desktop.
compare_dates_post_draft
function test_single_page() {
$post_id = get_the_ID();
$closing_date = get_post_meta($post_id,'closing_date',true);
if($closing_date!='') {
$today = date("Y-m-d");
$expire = date("Y-m-d",strtotime($closing_date)) ;
$today_dt = new DateTime($today);
$expire_dt = new DateTime($expire);
if ($expire_dt < $today_dt) {
$post = array( 'ID' => $post_id, 'post_status' => 'Draft' );
wp_update_post($post);
// redirect
header('Location:'.get_site_url().'/jobs-overview/');
exit();
die();
}
}
}
add_action('wp_head', 'test_single_page');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment