Support

Account

Home Forums General Issues Date Picker [From – To] Expire Events

Unread

Date Picker [From – To] Expire Events

  • Hi, I am trying to use the date picker to hide my event posts. Some events are one day events and some are multiple day events, and what I am trying to do Is have the post end on the “end-date”, and If “end_date” Is not selected I need It to end on the “start_date”. At the moment It works on the “end-date”, but I need It to work on “start_date: IF “end-date” Is not entered.

    if ($expireTransient = get_transient($post->ID) === false) {
    
        set_transient($post->ID, 'set for 1 minutes', 1);
        $today = date('M j, Y');
        $args = array(
            'post_type' => 'event',
            'posts_per_page' => 200,
            'post_status' => 'publish',
            'meta_query' => array(
                array(
                    'key' => 'end_date',
                    'value' => $today,
                    'type' => 'DATE',
                    'compare' => '<='
                ),
                array(
                    'key' => 'start_date',
                    'value' => $today,
                    'type' => 'DATE',
                    'compare' => '<='
                ),
            )
        );
        
    
        $posts = get_posts($args);
    
        foreach( $posts as $post ) {
            if(get_field('end_date', $post->ID) == $today) {
                $postdata = array(
                    'ID' => $post->ID,
                    'post_status' => 'trash'
                );
                wp_update_post($postdata);
    
            } elseif (get_field('start_date', $post->ID) == $today) {
                    $postdata = array(
                        'ID' => $post->ID,
                        'post_status' => 'draft'
                    );
                    wp_update_post($postdata);
            }
        }
    }

    Thank you!

    Maks

Viewing 1 post (of 1 total)

The topic ‘Date Picker [From – To] Expire Events’ is closed to new replies.