Hi Igor, Can you help me with a code where when the coupon code expires, the date of that post is automatically set to some date in 2019?
I tried the below code, but it is not working
add_action('post_change_expired', 'post_change_expired_function', 10, 1);
if (!function_exists('post_change_expired_function')) {
function post_change_expired_function($expired=''){
global $post;
if (isset($post)){
$post_id = $post->ID;
}
else{
return false; // Error: no POST ID
}
$expired_exist = get_post_meta($post_id, 're_post_expired', true);
if($expired == 1 && $expired_exist != 1){
update_post_meta($post_id, 're_post_expired', 1);
wp_set_object_terms($post_id, 'yes', 'offerexpiration', false );
// Set the post date to January 1, 2020
$new_date = '2020-01-01 00:00:00';
$postarr = array(
'ID' => $post_id,
'post_date' => $new_date,
'post_date_gmt' => get_gmt_from_date($new_date)
);
wp_update_post($postarr);
} elseif($expired == 'no'){
update_post_meta($post_id, 're_post_expired', 0);
wp_set_object_terms($post_id, NULL, 'offerexpiration', false );
} elseif($expired_exist == 0){
// No action needed if not expired
} elseif($expired_exist == ''){
update_post_meta($post_id, 're_post_expired', 0);
wp_set_object_terms($post_id, NULL, 'offerexpiration', false );
}
}
}
To drift around turns without falling off the track is Drift Boss' mission. Sounds easy, right? As you progress, it gets harder. Soon, you'll need to master every corner to unlock the best rides.