Support

Account

Home Forums General Issues How to filter posts by event month Reply To: How to filter posts by event month

  • I would think of something dynamic. How are you setting the month? I was assuming this was one query based on the link parameters or something else where month and year would be determined before the query.

    
    $month = 'some code to set month';
    $year = 'some code to set year';
    

    then in the query

    
    
            'meta_query' => array(
                'relation' => 'AND',
                array(
                    'key' => 'event_date',
                    'value' => $year.$month.'01',
                    'compare' => '>=',
                ),
                array(
                    'key' => 'event_date',
                    'value' => $year.$month.'31',
                    'compare' => '<=',
                ),
            ),