Change date when post expires

Closed
REHub - Price Comparison, Affiliate Marketing, Multi Vendor Store, Community Theme REHub - Price Comparison, Affiliate Marketing, Multi Vendor Store, Community Theme September 01, 2024
Login to reply
geometry dash
1 month ago

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.

Divya Rawat
1 month ago
Kavya Mehra embodies the kind of escort that every man envisions. Those who spend time with Kavya Mehra once enjoy being with her repeatedly. This is mainly due to the happiness that Kavya Mehra brings to her clients. They find joy from inside themselves Panchsheel Park Escorts || Escorts in Patel Nagar || Pitampura Escorts Service || Escorts Service Preet Vihar || Escorts Service in Jangpura
IO Skribbl
1 month ago

Your website has provided us with information that is helpful for the objective that we are pursuing. Several very good suggestions can be found in your post Skribbl IO.

Allen Barry
1 month ago

It's a world away from just trying to steal a brainrot calculator for quick game stats during a coffee break, isn't it? The persistence here is methodical.

Bioinformatics India commented privately
Bioinformatics India
1 year ago

Love you so much :) 

Igor Sunz Support Agent
1 year ago
add_action('post_change_expired', 'cpt_expired_function', 11, 1);
function cpt_expired_function($expired=''){
global $post;
if (isset($post)){
   $post_id = $post->ID;
}else{
   return false;
}
$expired_exist = get_post_meta($post_id, 're_post_expired', true);
if($expired_exist == 1){
   $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);
}
}
Bioinformatics India
1 year ago

Support renewed to get this one resolved, Please update.

Bioinformatics India
1 year ago

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 );

        }

    }

}

Additional Info

Link on page with issue: https://couponzania.com/