How to select events within current week using wp_query

I'm trying to create an events page that lists events (custom post type) within the week. I'm having trouble properly selecting only the posts that have a 'start_date' that falls in the current week.

Here is my code:

    $day = date('w');
    $week_start = date('d-m-Y', strtotime('-'. $day . ' days'));
    $week_end = date('d-m-Y', strtotime('+' . (6 - $day) . ' days'));

    $args = array(
        'post_type' = 'hcc_events',
        'order' = 'ASC',
        'meta_key' = 'start_date',
        'orderby' = 'meta_value',
        'posts_per_page' = -1,
        'meta_query' = array(
            'relation' = 'AND',
            array(
                'key' = 'start_date',
                'value' = $week_start,
                'compare' = '=',
                'type' = 'DATE'
            ),
            array(
                'key' = 'start_date',
                'value' = $week_end,
                'compare' = '=',
                'type' = 'DATE'
            )
        )
    );

Right now nothing is output at all. Any help is appreciated!

Topic wp-query events Wordpress

Category Web


This is simple way provided by wordpress:

$loop = new WP_Query(
    array(
        'post_type' => 'custom_post_type',
        'posts_per_page' => 7,
        'meta_key' => 'meta_key',
        'orderby' => 'meta_value_num',
        'date_query' => array(
            'date_query' => array(
                array(
                    'year' => date('Y'),
                    'week' => date('W'),
                ),
            ),
        ),

    )
);

Changing the date format to Y-m-d on ACF and in my code was what fixed everything!

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.