my site uses custom posts for events. The event post is deleted daily on the day of the event. I would like to slightly alter the deletion of the events to be the day of the event but in the evening. Even the following day 12.01am would be fine. Can anyone advise how to achieve this?

I think I have identified the bit of code I need to adjust:

if (!wp_next_scheduled('expire_posts')) {
    wp_schedule_event(time(), 'daily', 'expire_posts');

function set_post_status_func() {
    $today = time();

    $args = array(
        'post_type' => array('event'),
        'posts_per_page' => -1

    $posts = get_posts($args);

    foreach($posts as $p) {
        $eventYear = get_field('event_year', $p->ID);
        $eventMonth = get_field('event_month', $p->ID);
        $eventDay = get_field('event_day', $p->ID);
        $eventDate = strtotime($eventDay . ' ' . $eventMonth . ' ' . $eventYear);

        if ($eventDate ID, true);

add_action('expire_posts', 'set_post_status_func');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.