Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Rebecca Jensen
Rebecca Jensen
11,568 Points

Posts are expiring too soon in PHP/Wordpress

I use this bit of code below to display upcoming events, and hide them once the date has passed.

It seemed to work correctly, until we had an evening event, and I discovered that the posts were expiring hours too soon! I have the proper timezone set in my Wordpress settings (Vancouver/Seattle), but that does not seem to make a difference.

I need to either fix the time zone problem, or overshoot and have the event expire the NEXT day. Any idea on how I can accomplish either?

<?php
        $query = new WP_Query( array(

            'post_type' => 'event',
            'nopaging' => 'true',
            'meta_key'   => 'event_date',
            'orderby'    => 'meta_value_num',
            'order'      => 'ASC',
            'meta_value'    => date('Ymd'),
            'meta_compare'  => '>=',
            'date_query'    => array(
                array(
                        'key' => 'date',
                        'value' => date('Ymd'),
                        'compare' => '>=', //Greater than or equal to
                        'type' => 'DATETIME'
                    )
                ),
            ) );
        ?>