I’ve a working script to “expire” a submit based mostly on the info of a customized discipline. The submit “expires” (standing adjustments to a customized standing archived
) on the identical day because the event_end_date
date.
As a substitute, I would love the submit standing to be modified the day AFTER the event_end_date
date. I attempted to change my script but it surely’s not working… I do not know PHP, I am simply attempting to decipher it from present code and net searches.
My preliminary script which works to vary the submit standing on the identical day as event_end_date
:
// expire occasions on date discipline.
if (!wp_next_scheduled('hol_expire_events')){
wp_schedule_event(time(), 'day by day', 'hol_expire_events'); // this may be hourly, twicedaily, or day by day
}
add_action('hol_expire_events', 'hol_expire_events_function');
perform hol_expire_events_function() {
$as we speak = date('Y-m-d');
$args = array(
'post_type' => array('occasion'), // submit varieties you wish to test
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$expiredate = get_post_meta($p->ID, 'event_end_date', true ); // get the date from the db
if ($expiredate) {
if($expiredate < $as we speak){
$postdata = array(
'ID' => $p->ID,
'post_status' => 'archived'
);
wp_update_post($postdata);
}
}
}
}
And under is my up to date script, with an try to vary the expiring date to the DAY AFTER the date in event_end_date
:
// expire occasions on date discipline.
if (!wp_next_scheduled('hol_expire_events')){
wp_schedule_event(time(), 'day by day', 'hol_expire_events'); // this may be hourly, twicedaily, or day by day
}
add_action('hol_expire_events', 'hol_expire_events_function');
perform hol_expire_events_function() {
$nextday = date('Y-m-d', strtotime("+1 day"));
$args = array(
'post_type' => array('occasion'), // submit varieties you wish to test
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$expiredate = get_post_meta($p->ID, 'event_end_date', true ); // get the date from the db
if ($expiredate) {
if($expiredate < $nextday){
$postdata = array(
'ID' => $p->ID,
'post_status' => 'archived'
);
wp_update_post($postdata);
}
}
}
}
It’s sadly not working, and I am unsure why. After I run the cron for that perform, it nonetheless ‘expires’ the submit on the identical day as event_end_date
as a substitute of on event_end_date
+ 1 day.
Would anybody be capable of assist? Thanks upfront.